CREATE OR REPLACE VIEW Actual_hands_view AS select `a`.`company_id` AS `company_id`,`a`.`Deptcode` AS `Deptcode`,`a`.`Deptdesc` AS `Deptdesc`,`a`.`Date` AS `Date`,`a`.`designation` AS `designation`,`a`.`ShiftA` AS `ShiftA`,`a`.`ShiftB` AS `ShiftB`,`a`.`ShiftC` AS `ShiftC`,((`a`.`ShiftA` + `a`.`ShiftB`) + `a`.`ShiftC`) AS `Total` from (select `vowsls`.`daily_attendance`.`company_id` AS `company_id`,`vowsls`.`department_master`.`dept_code` AS `Deptcode`,`vowsls`.`department_master`.`dept_desc` AS `Deptdesc`,`vowsls`.`designation`.`desig` AS `designation`,`vowsls`.`daily_attendance`.`attendance_date` AS `Date`,round(sum((case when concat((`vowsls`.`daily_attendance`.`spell` = 'A1'),'A2') then (`vowsls`.`daily_attendance`.`working_hours` / 8) else 0 end)),1) AS `ShiftA`,round(sum((case when concat((`vowsls`.`daily_attendance`.`spell` = 'B1'),'B2') then (`vowsls`.`daily_attendance`.`working_hours` / 8) else 0 end)),1) AS `ShiftB`,round(sum((case when concat((`vowsls`.`daily_attendance`.`spell` = 'C')) then (`vowsls`.`daily_attendance`.`working_hours` / 8) else 0 end)),1) AS `ShiftC` from ((`vowsls`.`daily_attendance` join `vowsls`.`department_master` on((`vowsls`.`daily_attendance`.`worked_department_id` = `vowsls`.`department_master`.`dept_id`))) join `vowsls`.`designation` on((`vowsls`.`designation`.`id` = `vowsls`.`department_master`.`dept_id`))) where ((`vowsls`.`daily_attendance`.`attendance_date` = '2020-11-22') and (`vowsls`.`daily_attendance`.`company_id` = 1)) group by `Deptcode`,`Deptdesc`,`designation`,`vowsls`.`daily_attendance`.`company_id` order by `Deptcode`) `a`;;
CREATE OR REPLACE VIEW Billpass_report AS select `vowsls`.`bill_pass`.`company_id` AS `Company_id`,`vowsls`.`bill_pass`.`fin_year` AS `ac_year`,cast(`vowsls`.`bill_pass`.`bill_date` as date) AS `Billdate`,`vowsls`.`bill_pass`.`bill_no` AS `billno`,`vowsls`.`billpass_line_items`.`description` AS `Description`,`vowsls`.`billpass_line_items`.`uom` AS `Unit`,`vowsls`.`billpass_line_items`.`rate` AS `Rate`,`vowsls`.`bill_pass`.`invoice_no` AS `Invoiceno`,cast(`vowsls`.`bill_pass`.`payment_due_date` as date) AS `paymentduedate`,cast(`vowsls`.`bill_pass`.`invoice_recieved_date` as date) AS `invoicerecieveddate`,`vowsls`.`bill_pass`.`tcs_percentage` AS `tcspercentage`,cast(`vowsls`.`bill_pass`.`invoice_date` as date) AS `invoicedate`,sum(`vowsls`.`bill_pass`.`invoice_amount`) AS `Invoiceamount`,round(sum(`vowsls`.`billpass_line_items`.`igst_amount`),0) AS `Igst`,round(sum(`vowsls`.`billpass_line_items`.`cgst_amount`),0) AS `Cgst`,round(sum(`vowsls`.`billpass_line_items`.`sgst_amount`),0) AS `Sgst`,sum(`vowsls`.`billpass_line_items`.`qty`) AS `Quantity`,sum((`vowsls`.`billpass_line_items`.`rate` * `vowsls`.`billpass_line_items`.`qty`)) AS `Amount`,`vowsls`.`costmaster`.`cost_desc` AS `costcenter`,`vowsls`.`suppliermaster`.`supp_name` AS `Vendor`,`vowsls`.`type_master`.`type_desc` AS `taxtype` from ((((`vowsls`.`bill_pass` join `vowsls`.`billpass_line_items` on((`vowsls`.`bill_pass`.`bill_pass_trans_no` = `vowsls`.`billpass_line_items`.`bill_pass_hdr_id`))) join `vowsls`.`costmaster` on(((`vowsls`.`costmaster`.`id` = `vowsls`.`billpass_line_items`.`cost_center_id`) and (`vowsls`.`costmaster`.`company_id` = `vowsls`.`billpass_line_items`.`company_id`)))) join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`bill_pass`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`bill_pass`.`company_id`)))) join `vowsls`.`type_master` on((`vowsls`.`type_master`.`type_id` = `vowsls`.`bill_pass`.`tax_type`))) where (`vowsls`.`bill_pass`.`bill_type` = 'o') group by `vowsls`.`bill_pass`.`company_id`,`ac_year`,`Billdate`,`Unit`,`vowsls`.`billpass_line_items`.`rate`,`vowsls`.`billpass_line_items`.`description`,`Invoiceno`,`paymentduedate`,`invoicerecieveddate`,`tcspercentage`,`invoicedate`,`billno`,`costcenter`,`Vendor`,`taxtype`;;
CREATE OR REPLACE VIEW ConsumptionReport AS select `hdr`.`company_id` AS `Company_id`,`hdr`.`fin_year` AS `Fin_year`,`pro`.`prj_name` AS `Project`,`branch`.`branch_name` AS `Phase`,`indent`.`indent_type_desc` AS `Type`,`item`.`group_desc` AS `Item_Group`,`Maste`.`item_desc` AS `Item_Name`,`hdr`.`uom_code` AS `Uom`,sum(`hdr`.`req_by`) AS `Requested By`,`hdr`.`req_date` AS `Requisition_Date`,sum(`hdr`.`req_quantity`) AS `Requested Quantity`,`user`.`user_login_id` AS `Issued By`,sum(`hdr`.`issue_qty`) AS `Issued Quantity`,sum(`Retrn`.`return_qty`) AS `Returned Quantity` from ((((((((`vowsls`.`scm_issue_hdr` `hdr` join `vowsls`.`project_master` `pro` on((`hdr`.`project_id` = `pro`.`prj_id`))) join `vowsls`.`branch_master` `branch` on((`hdr`.`branch_id` = `branch`.`branch_id`))) join `vowsls`.`scm_indent_type_master` `indent` on(((`hdr`.`indent_type_id` = `indent`.`indent_type_code`) and (`indent`.`company_id` = `hdr`.`company_id`)))) left join `vowsls`.`item_group_master` `item` on((`item`.`group_code` = `hdr`.`group_code`))) join `vowsls`.`itemmaster` `Maste` on(((`hdr`.`item_code` = `Maste`.`item_code`) and (`Maste`.`company_id` = `hdr`.`company_id`) and (`Maste`.`group_code` = `hdr`.`group_code`)))) join `vowsls`.`user_details` `user` on(((`user`.`user_id` = `hdr`.`user_1`) and (`user`.`company_id` = `hdr`.`company_id`)))) join `vowsls`.`scm_return_hdr` `Retrn` on(((`Retrn`.`item_code` = `hdr`.`item_code`) and (`Retrn`.`company_id` = `hdr`.`company_id`) and (`Retrn`.`group_code` = `hdr`.`group_code`)))) join `vowsls`.`scm_sr_line_item` `line_item` on((`hdr`.`item_code` = `line_item`.`item_code`))) group by `hdr`.`company_id`,`hdr`.`fin_year`,`Project`,`Phase`,`Type`,`Item_Group`,`Item_Name`,`Uom`,`Requisition_Date`,`Issued By`,`hdr`.`issue_date`;;
CREATE OR REPLACE VIEW Consumption_Report_IS05 AS select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,concat(`vowsls`.`scm_issue_hdr`.`group_code`,`vowsls`.`scm_issue_hdr`.`item_code`) AS `ItemCode`,`vowsls`.`itemmaster`.`item_desc` AS `Description`,`vowsls`.`scm_issue_hdr`.`uom_code` AS `Uom`,`vowsls`.`scm_issue_hdr`.`issue_date` AS `issuedate`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_qty`),0) AS `Quantity`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),0) AS `Amount`,`vowsls`.`mechine_master`.`mechine_name` AS `machinename` from ((`vowsls`.`scm_issue_hdr` join `vowsls`.`itemmaster` on(((`vowsls`.`scm_issue_hdr`.`item_code` = `vowsls`.`itemmaster`.`item_code`) and (`vowsls`.`scm_issue_hdr`.`group_code` = `vowsls`.`itemmaster`.`group_code`) and (`vowsls`.`scm_issue_hdr`.`company_id` = `vowsls`.`itemmaster`.`company_id`)))) join `vowsls`.`mechine_master` on((`vowsls`.`mechine_master`.`mechine_id` = `vowsls`.`scm_issue_hdr`.`machine_id`))) group by `vowsls`.`scm_issue_hdr`.`company_id`,`ac_year`,`ItemCode`,`Description`,`Uom`,`machinename`,`issuedate`;;
CREATE OR REPLACE VIEW Consumption_Report_view AS select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,`vowsls`.`project_master`.`prj_name` AS `prj_name`,`vowsls`.`branch_master`.`branch_name` AS `branch_name`,`vowsls`.`item_group_master`.`group_desc` AS `group_desc`,`vowsls`.`itemmaster`.`item_desc` AS `item_desc`,`vowsls`.`itemmaster`.`sr_rate` AS `Rate`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_qty`),0) AS `issueqty`,`vowsls`.`user_details`.`user_login_id` AS `Issueby`,`vowsls`.`scm_issue_hdr`.`issue_date` AS `Date`,`vowsls`.`scm_issue_hdr`.`uom_code` AS `UOM`,`vowsls`.`scm_indent_type_master`.`indent_type_desc` AS `indent_type_desc`,sum(`vowsls`.`scm_return_hdr`.`return_qty`) AS `Returnqty`,sum(`vowsls`.`scm_issue_hdr`.`req_quantity`) AS `Reqqty`,`vowsls`.`scm_issue_hdr`.`req_date` AS `rDate`,`vowsls`.`scm_issue_hdr`.`req_by` AS `Requestby`,`vowsls`.`scm_return_hdr`.`return_date` AS `return_date`,`vowsls`.`scm_return_hdr`.`created_by` AS `Returnby`,round((case when sum((`vowsls`.`scm_return_hdr`.`return_qty` is null)) then sum(`vowsls`.`scm_issue_hdr`.`issue_qty`) end),1) AS `consumedqty` from (((((((`vowsls`.`scm_issue_hdr` join `vowsls`.`project_master` on((`vowsls`.`scm_issue_hdr`.`project_id` = `vowsls`.`project_master`.`prj_id`))) join `vowsls`.`branch_master` on((`vowsls`.`branch_master`.`branch_id` = `vowsls`.`scm_issue_hdr`.`branch_id`))) left join `vowsls`.`scm_indent_type_master` on((`vowsls`.`scm_indent_type_master`.`indent_type_code` = `vowsls`.`scm_issue_hdr`.`indent_type_id`))) left join `vowsls`.`scm_return_hdr` on((`vowsls`.`scm_return_hdr`.`issue_rec_id` = `vowsls`.`scm_issue_hdr`.`issue_no`))) left join `vowsls`.`user_details` on((`vowsls`.`user_details`.`user_id` = `vowsls`.`scm_issue_hdr`.`user_1`))) left join `vowsls`.`item_group_master` on(((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_issue_hdr`.`group_code`) and (`vowsls`.`item_group_master`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`)))) left join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_issue_hdr`.`item_code`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_issue_hdr`.`group_code`)))) group by `vowsls`.`scm_issue_hdr`.`company_id`,`ac_year`,`vowsls`.`project_master`.`prj_name`,`vowsls`.`branch_master`.`branch_name`,`vowsls`.`item_group_master`.`group_desc`,`vowsls`.`itemmaster`.`item_desc`,`vowsls`.`scm_indent_type_master`.`indent_type_desc`,`vowsls`.`scm_return_hdr`.`return_date`,`Date`,`Requestby`,`Issueby`,`Returnby`,`rDate`,`UOM`,`Rate`;;
CREATE OR REPLACE VIEW IS23_Store_Consumption AS select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,concat(`vowsls`.`scm_sr_line_item`.`item_grp_id`,`vowsls`.`scm_sr_line_item`.`item_code`) AS `ItemCode`,round(sum(`vowsls`.`scm_sr_line_item`.`final_qty`),0) AS `totalqty`,round(avg(`vowsls`.`scm_sr_line_item`.`final_qty`),0) AS `avgqty`,round(sum((`vowsls`.`scm_sr_line_item`.`final_qty` * `vowsls`.`scm_sr_line_item`.`rate`)),0) AS `totalvalue`,round(avg((`vowsls`.`scm_sr_line_item`.`final_qty` * `vowsls`.`scm_sr_line_item`.`rate`)),0) AS `avgvalue`,`vowsls`.`itemmaster`.`item_desc` AS `Description` from ((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_sr_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`ItemCode`,`vowsls`.`itemmaster`.`item_desc`;;
CREATE OR REPLACE VIEW Indent_Details_view AS select `h`.`company_id` AS `company_id`,`h`.`fin_year` AS `fin_year`,`h`.`indent_no` AS `INDENT_NO`,cast(`h`.`indent_date` as date) AS `IndentDate`,`vowsls`.`project_master`.`prj_name` AS `prj_name`,`vowsls`.`branch_master`.`branch_name` AS `branch_name`,`sm`.`status_name` AS `Indentstatus`,`l`.`indent_srl_no` AS `INDENT_SRL_NO`,`l`.`indent_qty` AS `INDENT_QTY`,`l`.`uom_code` AS `UOM_CODE`,`pl`.`quantity` AS `poQuantity`,`pl`.`line_item_num` AS `LINE_ITEM_NUM`,`ph`.`po_date` AS `PO_DATE`,`ph`.`po_num` AS `po_num`,`sp`.`status_name` AS `Ordersattus`,`sl`.`store_line_item_no` AS `STORE_LINE_ITEM_NO`,`sl`.`actual_quantity` AS `srQuantity`,`sh`.`store_receive_no` AS `STORE_RECEIVE_NO`,cast(`sh`.`store_receive_dt` as date) AS `SRdate`,`ss`.`status_name` AS `SRstatus`,`i`.`item_code` AS `item_code`,`i`.`sr_rate` AS `rate`,`i`.`item_desc` AS `item_desc`,`ig`.`group_code` AS `group_code`,`ig`.`group_desc` AS `group_desc`,`gl`.`dtl_id` AS `DTL_ID` from (((((((((((((`vowsls`.`scm_indent_hdr` `h` join `vowsls`.`scm_indent_line_item` `l` on(((`h`.`indent_no` = `l`.`indent_no`) and (`h`.`fin_year` = `l`.`fin_year`) and (`h`.`company_id` = `l`.`company_id`)))) left join `vowsls`.`scm_po_line_item` `pl` on((`pl`.`indent_no` = `l`.`indent_srl_no`))) left join `vowsls`.`scm_po_hdr` `ph` on((`ph`.`po_num` = `pl`.`po_num`))) left join `vowsls`.`project_master` on((`vowsls`.`project_master`.`prj_id` = `h`.`project_id`))) left join `vowsls`.`branch_master` on((`vowsls`.`branch_master`.`branch_id` = `h`.`branch_id`))) join `vowsls`.`itemmaster` `i` on(((`i`.`item_code` = `l`.`item_code`) and (`l`.`company_id` = `i`.`company_id`) and (`l`.`group_code` = `i`.`group_code`)))) join `vowsls`.`item_group_master` `ig` on(((`ig`.`group_code` = `l`.`group_code`) and (`ig`.`company_id` = `l`.`company_id`) and (`i`.`group_code` = `ig`.`group_code`)))) left join `vowsls`.`gate_store_entry_reg_dtl` `gl` on((`gl`.`po_line_no` = `pl`.`line_item_num`))) left join `vowsls`.`scm_sr_line_item` `sl` on((`sl`.`gate_line_item_no` = `gl`.`dtl_id`))) left join `vowsls`.`scm_sr_hdr` `sh` on((`sh`.`store_receive_no` = `sl`.`store_receive_no`))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `h`.`indent_status`))) left join `vowsls`.`status_master` `sp` on((`sp`.`status_id` = `ph`.`po_status`))) left join `vowsls`.`status_master` `ss` on((`ss`.`status_id` = `sh`.`sr_good_recept_status`))) where ((`h`.`indent_type` <> 'J') and (`ph`.`po_type` <> 'J'));;
CREATE OR REPLACE VIEW Individual_splyr_wise AS select `a`.`company_id` AS `company_id`,`a`.`ac_year` AS `ac_year`,`a`.`srno` AS `srno`,`a`.`supplierinvoiceno` AS `supplierinvoiceno`,`a`.`Supplier` AS `Supplier`,`a`.`date` AS `date`,`a`.`Itemdescription` AS `Itemdescription`,`a`.`ItemCode` AS `ItemCode`,`a`.`qty` AS `qty`,`a`.`Unit` AS `Unit`,`a`.`Rate` AS `Rate`,`a`.`Totalvalue` AS `Totalvalue`,`a`.`cgst` AS `cgst`,`a`.`sgst` AS `sgst`,((`a`.`Totalvalue` + `a`.`cgst`) + `a`.`sgst`) AS `Netsrvalue` from (select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,`vowsls`.`scm_sr_hdr`.`store_receive_no` AS `srno`,cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date) AS `date`,round(sum(`vowsls`.`scm_sr_line_item`.`final_qty`),1) AS `qty`,`vowsls`.`itemmaster`.`item_desc` AS `Itemdescription`,`vowsls`.`itemmaster`.`item_code` AS `ItemCode`,`vowsls`.`scm_sr_line_item`.`rate` AS `Rate`,sum(ifnull(`vowsls`.`scm_sr_line_item`.`c_tax`,0)) AS `cgst`,sum(ifnull(`vowsls`.`scm_sr_line_item`.`s_tax`,0)) AS `sgst`,`vowsls`.`scm_sr_line_item`.`uom_code` AS `Unit`,round(sum(`vowsls`.`scm_sr_line_item`.`final_value`),1) AS `Totalvalue`,`vowsls`.`bill_pass`.`invoice_no` AS `supplierinvoiceno`,`vowsls`.`suppliermaster`.`supp_name` AS `Supplier` from ((((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on(((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`) and (`vowsls`.`scm_sr_line_item`.`is_active` = 1)))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_sr_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) join `vowsls`.`bill_pass` on(((`vowsls`.`bill_pass`.`sr_mr_num` = `vowsls`.`scm_sr_hdr`.`store_receive_no`) and (`vowsls`.`bill_pass`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`) and (`vowsls`.`bill_pass`.`bill_type` = 'S')))) join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`scm_sr_hdr`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`srno`,`date`,`Itemdescription`,`ItemCode`,`vowsls`.`scm_sr_line_item`.`rate`,`Unit`,`supplierinvoiceno`,`Supplier`) `a`;;
CREATE OR REPLACE VIEW Inventory_Report_view AS select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `fin_year`,`vowsls`.`project_master`.`prj_name` AS `project`,`vowsls`.`branch_master`.`branch_name` AS `branch`,`vowsls`.`scm_indent_type_master`.`indent_type_desc` AS `type`,`vowsls`.`item_group_master`.`group_desc` AS `Itemgroup`,`vowsls`.`itemmaster`.`item_desc` AS `Itemname`,`vowsls`.`scm_issue_hdr`.`uom_code` AS `unit`,round(sum(`vowsls`.`scm_sr_line_item`.`final_qty`),0) AS `Quantityreceived`,sum(`vowsls`.`scm_return_hdr`.`return_qty`) AS `ret`,sum(`vowsls`.`scm_issue_hdr`.`issue_qty`) AS `Issue`,round(sum(`vowsls`.`scm_sr_line_item`.`stock_transer_quantity`),0) AS `Transfer`,(case when sum((`vowsls`.`scm_return_hdr`.`return_qty` is null)) then sum(`vowsls`.`scm_issue_hdr`.`issue_qty`) end) AS `consumedqty`,sum(`vowsls`.`scm_po_line_item`.`quantity`) AS `QuantityOrdered` from (((((((((`vowsls`.`scm_issue_hdr` join `vowsls`.`project_master` on((`vowsls`.`scm_issue_hdr`.`project_id` = `vowsls`.`project_master`.`prj_id`))) left join `vowsls`.`branch_master` on((`vowsls`.`branch_master`.`branch_id` = `vowsls`.`scm_issue_hdr`.`branch_id`))) left join `vowsls`.`scm_return_hdr` on((`vowsls`.`scm_return_hdr`.`issue_rec_id` = `vowsls`.`scm_issue_hdr`.`issue_no`))) left join `vowsls`.`scm_indent_type_master` on((`vowsls`.`scm_indent_type_master`.`indent_type_code` = `vowsls`.`scm_issue_hdr`.`indent_type_id`))) left join `vowsls`.`item_group_master` on(((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_issue_hdr`.`group_code`) and (`vowsls`.`item_group_master`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`)))) left join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_issue_hdr`.`item_code`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_issue_hdr`.`group_code`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`)))) left join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_line_item`.`store_line_item_no` = `vowsls`.`scm_issue_hdr`.`sr_line_id`))) left join `vowsls`.`gate_store_entry_reg_dtl` on((`vowsls`.`scm_sr_line_item`.`gate_line_item_no` = `vowsls`.`gate_store_entry_reg_dtl`.`dtl_id`))) left join `vowsls`.`scm_po_line_item` on((`vowsls`.`scm_po_line_item`.`line_item_num` = `vowsls`.`gate_store_entry_reg_dtl`.`po_line_no`))) group by `vowsls`.`scm_issue_hdr`.`company_id`,`vowsls`.`scm_issue_hdr`.`fin_year`,`project`,`branch`,`type`,`Itemgroup`,`Itemname`,`unit`;;
CREATE OR REPLACE VIEW Item_Wise_Consumption AS select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,`vowsls`.`scm_issue_hdr`.`item_code` AS `Itemcode`,`vowsls`.`scm_issue_hdr`.`group_code` AS `Groupcode`,`vowsls`.`department_master`.`dept_desc` AS `Department`,`vowsls`.`scm_issue_hdr`.`issue_date` AS `date`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_qty`),0) AS `issue`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),0) AS `value`,`vowsls`.`item_group_master`.`group_desc` AS `Itemgroup`,`vowsls`.`itemmaster`.`item_desc` AS `Itemname` from (((`vowsls`.`itemmaster` join `vowsls`.`scm_issue_hdr` on((`vowsls`.`scm_issue_hdr`.`item_code` = `vowsls`.`itemmaster`.`item_code`))) join `vowsls`.`item_group_master` on(((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_issue_hdr`.`group_code`) and (`vowsls`.`item_group_master`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`item_group_master`.`group_code`)))) join `vowsls`.`department_master` on((`vowsls`.`department_master`.`dept_id` = `vowsls`.`scm_issue_hdr`.`dept_id`))) group by `vowsls`.`scm_issue_hdr`.`company_id`,`ac_year`,`Itemcode`,`Groupcode`,`date`,`Itemgroup`,`Itemname`,`Department`;;
CREATE OR REPLACE VIEW Item_wise_store AS select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,concat(`vowsls`.`scm_issue_hdr`.`group_code`,`vowsls`.`scm_issue_hdr`.`item_code`) AS `Itemcode`,`vowsls`.`master_department`.`dept_desc` AS `department`,`vowsls`.`costmaster`.`cost_desc` AS `costdesc`,`vowsls`.`item_group_master`.`group_desc` AS `Itemgroup`,`vowsls`.`itemmaster`.`item_desc` AS `Itemdesc`,`vowsls`.`scm_issue_hdr`.`issue_date` AS `Issuedate`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_qty`),0) AS `Issueqty`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),0) AS `Issueamount` from ((((`vowsls`.`scm_issue_hdr` join `vowsls`.`master_department` on(((`vowsls`.`scm_issue_hdr`.`dept_id` = `vowsls`.`master_department`.`mdept_id`) and (`vowsls`.`scm_issue_hdr`.`company_id` = `vowsls`.`master_department`.`company_id`)))) join `vowsls`.`costmaster` on(((`vowsls`.`costmaster`.`cost_code` = `vowsls`.`scm_issue_hdr`.`deptcost`) and (`vowsls`.`costmaster`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`)))) join `vowsls`.`item_group_master` on(((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_issue_hdr`.`group_code`) and (`vowsls`.`item_group_master`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`)))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_issue_hdr`.`item_code`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_issue_hdr`.`group_code`)))) group by `vowsls`.`scm_issue_hdr`.`company_id`,`ac_year`,`Itemcode`,`department`,`costdesc`,`Itemgroup`,`Itemdesc`,`Issuedate`;;
CREATE OR REPLACE VIEW Itemcode_wise_indent_report AS select `vowsls`.`scm_indent_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_indent_hdr`.`fin_year` AS `ac_year`,`vowsls`.`itemmaster`.`item_code` AS `ItemCode`,`vowsls`.`itemmaster`.`item_desc` AS `ItemDescription`,`vowsls`.`scm_indent_hdr`.`indent_date` AS `IndentDate`,`vowsls`.`scm_indent_hdr`.`indent_no` AS `IndentNO`,`vowsls`.`scm_po_hdr`.`po_num` AS `P.O.No`,`vowsls`.`scm_po_hdr`.`po_date` AS `P.O.Date` from ((`vowsls`.`scm_indent_hdr` join `vowsls`.`itemmaster` on((`vowsls`.`scm_indent_hdr`.`company_id` = `vowsls`.`itemmaster`.`company_id`))) join `vowsls`.`scm_po_hdr` on(((`vowsls`.`scm_po_hdr`.`hdr_id` = `vowsls`.`scm_indent_hdr`.`hdrid`) and (`vowsls`.`scm_po_hdr`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`))));;
CREATE OR REPLACE VIEW JUTE_ISSUE_REPORT AS select `j`.`company_id` AS `company_id`,`j`.`issue_date` AS `Issue Date`,`j`.`mr_no` AS `MrNo`,`q`.`jute_quality` AS `Quality`,`j`.`godown_no` AS `Godown`,`j`.`bale_loose` AS `Bale Loose`,`y`.`yarn_type` AS `Yarn Type`,round(sum((`j`.`issue_value` / `j`.`total_weight`)),0) AS `rate`,sum(`j`.`issue_value`) AS `Issue Value`,sum(`j`.`quantity`) AS `Quantity`,round(sum(`j`.`total_weight`),2) AS `Total Weight` from ((`vowsls`.`jute_issue` `j` join `vowsls`.`jute_quality_price_master` `q` on((`j`.`jute_quality` = `q`.`id`))) join `vowsls`.`yarn_type_master` `y` on((`y`.`yarn_type_id` = `j`.`yarn_type_id`))) where (`j`.`is_active` = 1) group by `j`.`company_id`,`j`.`issue_date`,`j`.`mr_no`,`q`.`jute_quality`,`j`.`godown_no`,`j`.`bale_loose`,`y`.`yarn_type`;;
CREATE OR REPLACE VIEW JUTE_MR_REPORT AS select `vowsls`.`scm_mr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_mr_hdr`.`ac_year` AS `ac_year`,cast(`vowsls`.`scm_mr_hdr`.`po_date` as date) AS `podate`,`vowsls`.`scm_mr_hdr`.`po_num` AS `ponumber`,`vowsls`.`scm_mr_hdr`.`jute_receive_no` AS `MRID`,`vowsls`.`scm_mr_hdr`.`mr_print_no` AS `mrno`,cast(`vowsls`.`scm_mr_hdr`.`jute_receive_dt` as date) AS `mrdate`,`vowsls`.`scm_mr_hdr`.`gate_entry_no` AS `gateentryno`,`vowsls`.`scm_mr_hdr`.`challan_no` AS `challanno`,cast(`vowsls`.`scm_mr_hdr`.`challan_date` as date) AS `challandate`,`vowsls`.`scm_mr_hdr`.`agent_name` AS `agent`,`vowsls`.`scm_mr_hdr`.`vehicle_no` AS `vehicleno`,(`vowsls`.`scm_mr_line_item`.`accepted_weight` / 100) AS `acceptedweight`,`vowsls`.`scm_mr_line_item`.`jute_issue_rate` AS `rate`,`vowsls`.`scm_mr_line_item`.`drums_consumed` AS `drums`,`vowsls`.`scm_mr_line_item`.`advised_weight` AS `advisedweight`,`vowsls`.`scm_mr_line_item`.`actual_weight` AS `millweight`,`vowsls`.`scm_mr_line_item`.`quantity_unit` AS `uom`,`vowsls`.`scm_mr_line_item`.`bale` AS `bales`,`vowsls`.`scm_mr_line_item`.`loose` AS `loose`,`vowsls`.`scm_mr_line_item`.`total_price` AS `amount`,`vowsls`.`scm_mr_line_item`.`claim_quality` AS `claimquality`,`vowsls`.`scm_mr_line_item`.`claim_rate` AS `cliamrate`,`vowsls`.`scm_mr_line_item`.`claim_dust` AS `cliamdust`,`vowsls`.`scm_mr_line_item`.`allowable_moisture` AS `qcmoisture`,`vowsls`.`scm_mr_hdr`.`unit_conversion` AS `type`,`vowsls`.`branch_master`.`branch_name` AS `branch`,`vowsls`.`itemmaster`.`item_desc` AS `description`,`bk`.`broker_name` AS `advisedbroker`,`bc`.`broker_name` AS `actualbroker`,`sa`.`supp_name` AS `advisedsupplier`,`sb`.`supp_name` AS `actualsupplier`,`vowsls`.`mukam`.`mukam_name` AS `mukamname`,`vowsls`.`status_master`.`status_name` AS `status`,`vowsls`.`warehouse_details`.`name` AS `warehousemae`,`vowsls`.`jute_quality_price_master`.`jute_quality` AS `quality` from (((((((((((`vowsls`.`scm_mr_hdr` join `vowsls`.`scm_mr_line_item` on((`vowsls`.`scm_mr_hdr`.`jute_receive_no` = `vowsls`.`scm_mr_line_item`.`jute_receive_no`))) join `vowsls`.`branch_master` on(((`vowsls`.`branch_master`.`branch_id` = `vowsls`.`scm_mr_hdr`.`branch_id`) and (`vowsls`.`branch_master`.`company_id` = `vowsls`.`scm_mr_hdr`.`company_id`)))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_mr_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_mr_hdr`.`company_id`)))) join `vowsls`.`broker_master` `bk` on((`bk`.`broker_id` = `vowsls`.`scm_mr_hdr`.`advised_broker`))) join `vowsls`.`broker_master` `bc` on((`bc`.`broker_id` = `vowsls`.`scm_mr_hdr`.`actual_broker`))) join `vowsls`.`suppliermaster` `sa` on(((`sa`.`supp_code` = `vowsls`.`scm_mr_hdr`.`supp_code`) and (`sa`.`company_id` = `vowsls`.`scm_mr_hdr`.`company_id`)))) join `vowsls`.`suppliermaster` `sb` on(((`sb`.`supp_code` = `vowsls`.`scm_mr_hdr`.`supp_code`) and (`sb`.`company_id` = `vowsls`.`scm_mr_hdr`.`company_id`)))) join `vowsls`.`mukam` on(((`vowsls`.`mukam`.`mukam_id` = `vowsls`.`scm_mr_hdr`.`mukam_id`) and (`vowsls`.`mukam`.`company_id` = `vowsls`.`scm_mr_hdr`.`company_id`)))) join `vowsls`.`status_master` on((`vowsls`.`status_master`.`status_id` = `vowsls`.`scm_mr_hdr`.`mr_good_recept_status`))) join `vowsls`.`warehouse_details` on((`vowsls`.`warehouse_details`.`id` = `vowsls`.`scm_mr_line_item`.`warehouse_no`))) join `vowsls`.`jute_quality_price_master` on((`vowsls`.`jute_quality_price_master`.`id` = `vowsls`.`scm_mr_line_item`.`actual_quality`))) where (`vowsls`.`itemmaster`.`group_code` = '999');;
CREATE OR REPLACE VIEW List_of_the_sales_order_value_supplied_invoice_value_widget AS select `a`.`company_id` AS `company_id`,`a`.`ac_year` AS `ac_year`,`a`.`salesorderno` AS `salesorderno`,`a`.`salesamount` AS `salesamount`,`a`.`numberofinvoice` AS `numberofinvoice`,`a`.`invoiceamount` AS `invoiceamount`,(`a`.`salesamount` - `a`.`invoiceamount`) AS `diff` from (select `vowsls`.`sales_order_hdr`.`company_id` AS `company_id`,`vowsls`.`sales_order_hdr`.`ac_year` AS `ac_year`,`vowsls`.`sales_order_hdr`.`sale_no_string` AS `salesorderno`,sum(`vowsls`.`sales_order_hdr`.`sale_amount`) AS `salesamount`,count(0) AS `numberofinvoice`,sum(`vowsls`.`invoice_hdr`.`invoice_amount`) AS `invoiceamount` from (`vowsls`.`sales_order_hdr` join `vowsls`.`invoice_hdr` on((`vowsls`.`sales_order_hdr`.`sale_no_string` = `vowsls`.`invoice_hdr`.`sale_no`))) group by `vowsls`.`sales_order_hdr`.`company_id`,`vowsls`.`sales_order_hdr`.`ac_year`,`salesorderno` order by `salesorderno` limit 10) `a`;;
CREATE OR REPLACE VIEW List_salesordervalue_invoicevalue AS select `vowsls`.`sales_order_hdr`.`company_id` AS `company_id`,`vowsls`.`sales_order_hdr`.`ac_year` AS `ac_year`,`vowsls`.`sales_order_hdr`.`sale_amount` AS `salesordervalue`,`vowsls`.`invoice_hdr`.`invoice_amount` AS `invoicevalue` from (`vowsls`.`sales_order_hdr` join `vowsls`.`invoice_hdr` on((`vowsls`.`sales_order_hdr`.`sale_no_string` = `vowsls`.`invoice_hdr`.`sale_no`)));;
CREATE OR REPLACE VIEW Month_Wise_Store_Consumption_Widgets AS select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),0) AS `value`,monthname(`vowsls`.`scm_issue_hdr`.`issue_date`) AS `mon`,extract(year_month from `vowsls`.`scm_issue_hdr`.`issue_date`) AS `montnme`,'consumption' AS `storepurchase` from `vowsls`.`scm_issue_hdr` group by `vowsls`.`scm_issue_hdr`.`company_id`,`ac_year`,`montnme`,`mon` order by `montnme`;;
CREATE OR REPLACE VIEW New_Stock_View AS select `h`.`company_id` AS `company_id`,`l`.`item_grp_id` AS `Itemgroup`,`l`.`item_code` AS `itemcode`,concat(`l`.`item_grp_id`,`l`.`item_code`) AS `itemuniqueno`,`i`.`item_desc` AS `Description`,`g`.`group_desc` AS `Groupdescription`,round(sum((`l`.`final_qty` - `l`.`quantity_consumed`)),3) AS `stockbal`,round(sum((`l`.`rate` * (`l`.`final_qty` - `l`.`quantity_consumed`))),3) AS `stockvalue`,max(cast(`h`.`store_receive_dt` as date)) AS `lastreceipt`,max(`sih`.`issue_date`) AS `lastissue`,(max(`sih`.`issue_date`) - max(cast(`h`.`store_receive_dt` as date))) AS `no_issue_days` from ((((`vowsls`.`scm_sr_hdr` `h` join `vowsls`.`scm_sr_line_item` `l` on((`h`.`store_receive_no` = `l`.`store_receive_no`))) join `vowsls`.`scm_issue_hdr` `sih` on(((`sih`.`sr_line_id` = `l`.`store_line_item_no`) and (`sih`.`group_code` = `l`.`item_grp_id`) and (`sih`.`item_code` = `l`.`item_code`) and (`sih`.`company_id` = `h`.`company_id`)))) join `vowsls`.`item_group_master` `g` on(((`g`.`group_code` = `l`.`item_grp_id`) and (`g`.`company_id` = `h`.`company_id`)))) join `vowsls`.`itemmaster` `i` on(((`i`.`group_code` = `l`.`item_grp_id`) and (`i`.`item_code` = `l`.`item_code`) and (`i`.`company_id` = `h`.`company_id`)))) group by `h`.`company_id`,`Itemgroup`,`itemcode`,`itemuniqueno`,`Groupdescription`,`i`.`item_desc`;;
CREATE OR REPLACE VIEW OrderReport AS select `vowsls`.`invoice_hdr`.`ac_year` AS `year`,`vowsls`.`invoice_hdr`.`company_id` AS `company`,`branch`.`branch_name` AS `Project`,`indent`.`indent_type_desc` AS `Type`,round(sum(`vowsls`.`invoice_line_items`.`quantity`),0) AS `delivered_quantity`,`vowsls`.`invoice_hdr`.`invoice_date` AS `Invoice_Date`,`vowsls`.`invoice_hdr`.`due_date` AS `invoice_certify_date`,monthname(`vowsls`.`invoice_hdr`.`invoice_date`) AS `monthname`,round(sum(`vowsls`.`invoice_hdr`.`grand_total`),0) AS `invoice_value_with_gst`,round(sum((`vowsls`.`invoice_hdr`.`grand_total` - `vowsls`.`invoice_hdr`.`tax_amount`)),0) AS `invoice_value_wo_gst`,round(sum(`vowsls`.`invoice_hdr`.`due_amount`),0) AS `payment_value_with_gst`,round(sum((`vowsls`.`invoice_hdr`.`grand_total` - `vowsls`.`invoice_hdr`.`due_amount`)),0) AS `balance_payment` from (((`vowsls`.`invoice_hdr` join `vowsls`.`invoice_line_items` on(((`vowsls`.`invoice_hdr`.`company_id` = `vowsls`.`invoice_line_items`.`company_id`) and (`vowsls`.`invoice_hdr`.`invoice_id` = `vowsls`.`invoice_line_items`.`invoice_id`)))) join `vowsls`.`branch_master` `branch` on((`branch`.`branch_id` = `vowsls`.`invoice_hdr`.`branch_id`))) join `vowsls`.`scm_indent_type_master` `indent` on((`indent`.`company_id` = `vowsls`.`invoice_hdr`.`company_id`))) group by `year`,`company`,`Project`,`Type`,`vowsls`.`invoice_hdr`.`invoice_date`,`monthname`,`invoice_certify_date` order by `vowsls`.`invoice_hdr`.`invoice_date`,`delivered_quantity`;;
CREATE OR REPLACE VIEW Order_Report_view AS select `vowsls`.`scm_indent_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_indent_hdr`.`fin_year` AS `ac_year`,`vowsls`.`project_master`.`prj_name` AS `Project`,`vowsls`.`branch_master`.`branch_name` AS `Branch`,`vowsls`.`scm_indent_type_master`.`indent_type_desc` AS `type`,cast(`vowsls`.`scm_indent_hdr`.`indent_date` as date) AS `Indentdate`,`vowsls`.`scm_indent_hdr`.`indent_no` AS `Indentno`,`vowsls`.`scm_indent_hdr`.`user_1` AS `Requestedby`,sum(`vowsls`.`scm_indent_line_item`.`quality`) AS `Requestedqty`,`vowsls`.`user_details`.`user_login_id` AS `user_login_id`,`vowsls`.`status_master`.`status_name` AS `Indentstatus`,`vowsls`.`scm_po_hdr`.`po_num` AS `Orderno`,`vowsls`.`scm_po_hdr`.`po_date` AS `Orderdate`,`vowsls`.`suppliermaster`.`supp_name` AS `Vendor`,`vowsls`.`item_group_master`.`group_desc` AS `Itemgroup`,`vowsls`.`itemmaster`.`item_desc` AS `Itemname`,`vowsls`.`scm_indent_line_item`.`uom_code` AS `Unit`,`vowsls`.`scm_indent_line_item`.`rate` AS `rate`,sum(`vowsls`.`scm_po_line_item`.`quantity`) AS `Orderqty`,sum(`vowsls`.`scm_po_line_item`.`value_wt_tax`) AS `Ordervaluewithgst`,sum(`vowsls`.`scm_po_line_item`.`value_wo_tax`) AS `Ordervaluewogst`,`vowsls`.`scm_po_hdr`.`expected_date` AS `deliverydateasperorder`,sum(`vowsls`.`gate_store_entry_reg_dtl`.`quantity`) AS `deliveredqty`,`vowsls`.`gate_store_entry_reg_hdr`.`in_date` AS `delivereddateactual`,cast(`vowsls`.`bill_pass`.`invoice_date` as date) AS `Invoicedate`,cast(`vowsls`.`bill_pass`.`mod_date_time` as date) AS `Invoicecertifydate`,`vowsls`.`bill_pass`.`bill_amount` AS `invocewithgst`,cast(`vowsls`.`bill_pass`.`payment_due_date` as date) AS `Paymentdate`,(`vowsls`.`bill_pass`.`bill_amount` - `vowsls`.`bill_pass`.`due_amount`) AS `Paymentvaluewithgst`,`vowsls`.`bill_pass`.`due_amount` AS `Balancepayment`,(`vowsls`.`bill_pass`.`bill_amount` - ((`vowsls`.`bill_pass`.`bill_amount` * `vowsls`.`bill_pass`.`tax_percentage`) / 100)) AS `Invoicewithougst` from (((((((((((((((`vowsls`.`scm_indent_hdr` join `vowsls`.`project_master` on(((`vowsls`.`project_master`.`prj_id` = `vowsls`.`scm_indent_hdr`.`project_id`) and (`vowsls`.`scm_indent_hdr`.`company_id` = `vowsls`.`project_master`.`company_id`)))) left join `vowsls`.`branch_master` on(((`vowsls`.`branch_master`.`branch_id` = `vowsls`.`scm_indent_hdr`.`branch_id`) and (`vowsls`.`branch_master`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`)))) left join `vowsls`.`scm_indent_type_master` on((`vowsls`.`scm_indent_type_master`.`indent_type_code` = `vowsls`.`scm_indent_hdr`.`indent_type`))) left join `vowsls`.`status_master` on((`vowsls`.`status_master`.`status_id` = `vowsls`.`scm_indent_hdr`.`indent_status`))) left join `vowsls`.`user_details` on((`vowsls`.`user_details`.`user_id` = `vowsls`.`scm_indent_hdr`.`user_1`))) left join `vowsls`.`scm_indent_line_item` on(((`vowsls`.`scm_indent_line_item`.`indent_no` = `vowsls`.`scm_indent_hdr`.`indent_no`) and (`vowsls`.`scm_indent_line_item`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`) and (`vowsls`.`scm_indent_line_item`.`fin_year` = `vowsls`.`scm_indent_hdr`.`fin_year`)))) left join `vowsls`.`item_group_master` on(((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_indent_line_item`.`group_code`) and (`vowsls`.`item_group_master`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`)))) left join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_indent_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_indent_line_item`.`group_code`)))) left join `vowsls`.`scm_po_line_item` on((`vowsls`.`scm_po_line_item`.`indent_no` = `vowsls`.`scm_indent_line_item`.`indent_srl_no`))) left join `vowsls`.`scm_po_hdr` on(((`vowsls`.`scm_po_hdr`.`po_num` = `vowsls`.`scm_po_line_item`.`po_num`) and (`vowsls`.`scm_po_hdr`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`)))) left join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`scm_po_hdr`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`)))) left join `vowsls`.`gate_store_entry_reg_dtl` on((`vowsls`.`gate_store_entry_reg_dtl`.`po_line_no` = `vowsls`.`scm_po_line_item`.`line_item_num`))) left join `vowsls`.`gate_store_entry_reg_hdr` on(((`vowsls`.`gate_store_entry_reg_hdr`.`hdr_id` = `vowsls`.`gate_store_entry_reg_dtl`.`hdr_id`) and (`vowsls`.`gate_store_entry_reg_hdr`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`)))) left join `vowsls`.`scm_sr_hdr` on(((`vowsls`.`scm_sr_hdr`.`gate_entry_no` = `vowsls`.`gate_store_entry_reg_hdr`.`hdr_id`) and (`vowsls`.`scm_sr_hdr`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`)))) left join `vowsls`.`bill_pass` on(((`vowsls`.`bill_pass`.`sr_mr_num` = `vowsls`.`scm_sr_hdr`.`store_receive_no`) and (`vowsls`.`bill_pass`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`)))) group by `vowsls`.`scm_indent_hdr`.`company_id`,`vowsls`.`scm_indent_hdr`.`fin_year`,`Project`,`Branch`,`type`,`Indentdate`,`Requestedby`,`vowsls`.`user_details`.`user_login_id`,`Indentstatus`,`Orderno`,`Orderdate`,`Vendor`,`Itemgroup`,`Itemname`,`Unit`,`vowsls`.`scm_indent_line_item`.`rate`,`deliverydateasperorder`,`delivereddateactual`,`Invoicedate`,`Invoicecertifydate`,`Invoicewithougst`,`invocewithgst`,`Paymentdate`,`Paymentvaluewithgst`,`Balancepayment`,`Indentno`;;
CREATE OR REPLACE VIEW Pending_Delivery_Widget AS select `p`.`po_date` AS `Po Date`,`p`.`po_num` AS `Po No`,`s`.`supp_name` AS `Supplier`,`i`.`item_desc` AS `Item Name`,(`l`.`quantity` - `l`.`gate_po_placed`) AS `Quantity`,round(sum(((`l`.`quantity` - `l`.`gate_po_placed`) * `l`.`rate`)),0) AS `value`,(to_days(curdate()) - to_days(`p`.`expected_date`)) AS `Due Days`,`p`.`company_id` AS `company_id`,`p`.`fin_year` AS `ac_year` from (((`vowsls`.`scm_po_hdr` `p` join `vowsls`.`scm_po_line_item` `l`) join `vowsls`.`suppliermaster` `s`) join `vowsls`.`itemmaster` `i`) where ((`p`.`po_num` = `l`.`po_num`) and ((`l`.`quantity` - `l`.`gate_po_placed`) > 0) and (cast(curdate() as date) > `p`.`expected_date`) and (`p`.`po_type` <> 'J') and (`s`.`supp_code` = `p`.`supp_code`) and (`s`.`company_id` = `p`.`company_id`) and (`l`.`item_code` = `i`.`item_code`) and (`l`.`is_active` = 1) and (`l`.`group_code` = `i`.`group_code`) and (`p`.`company_id` = `i`.`company_id`) and (`p`.`po_status` = 3)) group by `p`.`po_date`,`p`.`po_num`,`s`.`supp_name`,`p`.`company_id`,`p`.`fin_year`,`p`.`expected_date`,`i`.`item_desc`,(`l`.`quantity` - `l`.`gate_po_placed`) order by `Due Days` desc;;
CREATE OR REPLACE VIEW Recepit_Summary_Report AS select `vowsls`.`scm_mr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_mr_hdr`.`ac_year` AS `ac_year`,cast(`vowsls`.`scm_mr_hdr`.`jute_receive_dt` as date) AS `Good Recepit Date`,`vowsls`.`jute_quality_price_master`.`id` AS `ID`,`vowsls`.`jute_quality_price_master`.`jute_quality` AS `Jute Quality`,`vowsls`.`scm_mr_line_item`.`warehouse_no` AS `Ware House NO`,`vowsls`.`scm_mr_hdr`.`unit_conversion` AS `Unit Conversion`,round(sum(`vowsls`.`scm_mr_line_item`.`quantity`),0) AS `Quantity`,round(sum(`vowsls`.`scm_mr_line_item`.`actual_weight`),0) AS `Weight`,`vowsls`.`scm_mr_line_item`.`rate` AS `Rate` from ((`vowsls`.`scm_mr_hdr` join `vowsls`.`scm_mr_line_item` on((`vowsls`.`scm_mr_hdr`.`jute_receive_no` = `vowsls`.`scm_mr_line_item`.`jute_receive_no`))) join `vowsls`.`jute_quality_price_master` on((`vowsls`.`jute_quality_price_master`.`id` = `vowsls`.`scm_mr_line_item`.`actual_quality`))) group by `vowsls`.`scm_mr_hdr`.`company_id`,`vowsls`.`scm_mr_hdr`.`ac_year`,`Good Recepit Date`,`vowsls`.`jute_quality_price_master`.`id`,`Jute Quality`,`Ware House NO`,`Unit Conversion`,`vowsls`.`scm_mr_line_item`.`rate`;;
CREATE OR REPLACE VIEW SW_view_stock_widgets AS select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date) AS `date`,sum((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_issue_hdr`.`issue_qty`)) AS `openingstock`,sum((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_sr_line_item`.`quantity_consumed`)) AS `actualstock`,sum(`vowsls`.`scm_sr_line_item`.`quantity_consumed`) AS `consumedstock`,sum(`vowsls`.`scm_sr_line_item`.`stock_transer_quantity`) AS `traferstock`,sum(`vowsls`.`scm_sr_line_item`.`final_qty`) AS `receivedstock` from ((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`scm_issue_hdr` on((`vowsls`.`scm_issue_hdr`.`sr_line_id` = `vowsls`.`scm_sr_line_item`.`store_line_item_no`))) where ((month(cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date)) = month((curdate() - interval 1 month))) and (year(cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date)) = year((curdate() - interval 1 month)))) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`date` order by `date`;;
CREATE OR REPLACE VIEW Store_Bill_pass_report AS select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date) AS `srdate`,`vowsls`.`scm_sr_hdr`.`store_receive_no` AS `srno`,`vowsls`.`scm_sr_hdr`.`challan_no` AS `challanno`,`vowsls`.`scm_sr_hdr`.`challan_date` AS `challandate`,`vowsls`.`scm_sr_hdr`.`vehicle_no` AS `vehicleno`,`vowsls`.`scm_sr_hdr`.`good_type` AS `goodstype`,sum(`vowsls`.`scm_sr_line_item`.`final_qty`) AS `quantity`,concat(`vowsls`.`scm_sr_line_item`.`item_grp_id`,`vowsls`.`scm_sr_line_item`.`item_code`) AS `itemcode`,`vowsls`.`branch_master`.`branch_name` AS `branchname`,`vowsls`.`project_master`.`prj_name` AS `projectname`,`vowsls`.`scm_sr_line_item`.`uom_code` AS `uom`,`vowsls`.`scm_sr_line_item`.`warehouse_no` AS `warehouseno`,`vowsls`.`scm_sr_line_item`.`rate` AS `rate`,sum((`vowsls`.`scm_sr_line_item`.`final_qty` * `vowsls`.`scm_sr_line_item`.`rate`)) AS `amount`,`vowsls`.`item_group_master`.`group_desc` AS `itemgroup`,`vowsls`.`itemmaster`.`item_desc` AS `itemdescription`,`vowsls`.`bill_pass`.`bill_pass_trans_no` AS `billpassno`,`vowsls`.`bill_pass`.`po_num` AS `ponum`,`vowsls`.`bill_pass`.`po_date` AS `podate`,`vowsls`.`bill_pass`.`invoice_no` AS `Invoiceno`,cast(`vowsls`.`bill_pass`.`payment_due_date` as date) AS `paymentduedate`,cast(`vowsls`.`bill_pass`.`invoice_recieved_date` as date) AS `invoicerecieveddate`,`vowsls`.`bill_pass`.`tcs_percentage` AS `tcspercentage`,cast(`vowsls`.`bill_pass`.`invoice_date` as date) AS `invoicedate`,sum(`vowsls`.`bill_pass`.`invoice_amount`) AS `Invoiceamount`,cast(`vowsls`.`bill_pass`.`bill_date` as date) AS `billdate`,`vowsls`.`suppliermaster`.`supp_name` AS `suppiername` from (((((((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`branch_master` on((`vowsls`.`branch_master`.`branch_id` = `vowsls`.`scm_sr_hdr`.`branch_id`))) join `vowsls`.`project_master` on((`vowsls`.`project_master`.`prj_id` = `vowsls`.`scm_sr_hdr`.`project_id`))) join `vowsls`.`item_group_master` on(((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`) and (`vowsls`.`item_group_master`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`) and (`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_sr_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) join `vowsls`.`bill_pass` on(((`vowsls`.`bill_pass`.`sr_mr_num` = `vowsls`.`scm_sr_hdr`.`store_receive_no`) and (`vowsls`.`bill_pass`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`bill_pass`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`srdate`,`srno`,`challanno`,`challandate`,`vehicleno`,`goodstype`,`itemcode`,`branchname`,`projectname`,`itemgroup`,`itemdescription`,`billpassno`,`ponum`,`podate`,`billdate`,`suppiername`,`uom`,`warehouseno`,`vowsls`.`scm_sr_line_item`.`rate`,`Invoiceno`,`paymentduedate`,`invoicerecieveddate`,`tcspercentage`,`invoicedate`;;
CREATE OR REPLACE VIEW Store_Consumption_IS02 AS select `a`.`company_id` AS `company_id`,`a`.`DEPARTMENT` AS `DEPARTMENT`,`a`.`COSTCENTER` AS `COSTCENTER`,`a`.`Issuedate` AS `Issuedate`,`a`.`general` AS `general`,`a`.`overhauling` AS `overhauling`,`a`.`Maintainence` AS `Maintainence`,`a`.`capital` AS `capital`,`a`.`production` AS `production`,((((`a`.`production` + `a`.`general`) + `a`.`Maintainence`) + `a`.`overhauling`) + `a`.`capital`) AS `Total Cost` from (select `i`.`company_id` AS `company_id`,`md`.`dept_desc` AS `DEPARTMENT`,`cm`.`cost_desc` AS `COSTCENTER`,`i`.`issue_date` AS `Issuedate`,round(sum((case when (`i`.`indent_type_id` = 'G') then `i`.`issue_value` else 0 end)),0) AS `general`,round(sum((case when (`i`.`indent_type_id` = 'H') then `i`.`issue_value` else 0 end)),0) AS `overhauling`,round(sum((case when (`i`.`indent_type_id` = 'M') then `i`.`issue_value` else 0 end)),0) AS `Maintainence`,round(sum((case when (`i`.`indent_type_id` = 'P') then `i`.`issue_value` else 0 end)),0) AS `production`,sum((case when (`i`.`indent_type_id` = 'C') then `i`.`issue_value` else 0 end)) AS `capital` from ((`vowsls`.`scm_issue_hdr` `i` join `vowsls`.`master_department` `md` on(((`i`.`company_id` = `md`.`company_id`) and (`i`.`dept_id` = `md`.`mdept_id`)))) join `vowsls`.`costmaster` `cm` on(((`i`.`company_id` = `cm`.`company_id`) and (`i`.`deptcost` = `cm`.`id`)))) group by `i`.`company_id`,`DEPARTMENT`,`COSTCENTER`,`Issuedate`) `a`;;
CREATE OR REPLACE VIEW Store_Consumption_IS02A AS select `a`.`company_id` AS `company_id`,`a`.`issuedate` AS `issuedate`,`a`.`DEPARTMENT` AS `DEPARTMENT`,`a`.`general` AS `general`,`a`.`overhauling` AS `overhauling`,`a`.`Maintainence` AS `Maintainence`,`a`.`capital` AS `capital`,`a`.`production` AS `production`,((((`a`.`production` + `a`.`general`) + `a`.`Maintainence`) + `a`.`overhauling`) + `a`.`capital`) AS `Total Cost` from (select `i`.`company_id` AS `company_id`,`i`.`issue_date` AS `issuedate`,`md`.`dept_desc` AS `DEPARTMENT`,round(sum((case when (`i`.`indent_type_id` = 'G') then `i`.`issue_value` else 0 end)),0) AS `general`,round(sum((case when (`i`.`indent_type_id` = 'H') then `i`.`issue_value` else 0 end)),0) AS `overhauling`,round(sum((case when (`i`.`indent_type_id` = 'M') then `i`.`issue_value` else 0 end)),0) AS `Maintainence`,round(sum((case when (`i`.`indent_type_id` = 'P') then `i`.`issue_value` else 0 end)),0) AS `production`,sum((case when (`i`.`indent_type_id` = 'C') then `i`.`issue_value` else 0 end)) AS `capital` from (`vowsls`.`scm_issue_hdr` `i` join `vowsls`.`master_department` `md` on(((`i`.`company_id` = `md`.`company_id`) and (`i`.`dept_id` = `md`.`mdept_id`)))) group by `i`.`company_id`,`issuedate`,`DEPARTMENT`) `a`;;
CREATE OR REPLACE VIEW Store_Consumption_IS04 AS select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,concat(`vowsls`.`scm_issue_hdr`.`group_code`,`vowsls`.`scm_issue_hdr`.`item_code`) AS `itemcode`,`vowsls`.`itemmaster`.`item_desc` AS `Description`,`vowsls`.`master_department`.`dept_desc` AS `department`,`vowsls`.`scm_indent_type_master`.`indent_type_desc` AS `expensetype`,sum(`vowsls`.`scm_sr_line_item`.`rate`) AS `Rate`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_qty`),0) AS `YTD Quantity`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),0) AS `YTD Value` from ((((`vowsls`.`scm_issue_hdr` join `vowsls`.`itemmaster` on(((`vowsls`.`scm_issue_hdr`.`item_code` = `vowsls`.`itemmaster`.`item_code`) and (`vowsls`.`scm_issue_hdr`.`company_id` = `vowsls`.`itemmaster`.`company_id`) and (`vowsls`.`scm_issue_hdr`.`group_code` = `vowsls`.`itemmaster`.`group_code`)))) join `vowsls`.`scm_sr_line_item` on(((`vowsls`.`scm_sr_line_item`.`item_code` = `vowsls`.`scm_issue_hdr`.`item_code`) and (`vowsls`.`scm_sr_line_item`.`item_grp_id` = `vowsls`.`scm_issue_hdr`.`group_code`)))) join `vowsls`.`master_department` on((`vowsls`.`master_department`.`mdept_id` = `vowsls`.`scm_issue_hdr`.`dept_id`))) join `vowsls`.`scm_indent_type_master` on((`vowsls`.`scm_indent_type_master`.`indent_type_code` = `vowsls`.`scm_issue_hdr`.`indent_type_id`))) where ((year(`vowsls`.`scm_issue_hdr`.`issue_date`) = extract(year from curdate())) and (`vowsls`.`scm_indent_type_master`.`indent_type_code` <> 'J')) group by `vowsls`.`scm_issue_hdr`.`company_id`,`vowsls`.`scm_issue_hdr`.`fin_year`,`vowsls`.`itemmaster`.`item_desc`,`itemcode`,`expensetype`,`department`;;
CREATE OR REPLACE VIEW Store_Consumption_IS14 AS select `a`.`company_id` AS `company_id`,`a`.`ac_year` AS `ac_year`,`a`.`quantity` AS `quantity`,`a`.`Itemcode` AS `Itemcode`,`a`.`Description` AS `Description`,`a`.`unit` AS `unit`,sum((case when (`a`.`dat` = 'January') then `a`.`quantity` end)) AS `Jan`,sum((case when (`a`.`dat` = 'February') then `a`.`quantity` end)) AS `Feb`,sum((case when (`a`.`dat` = 'March') then `a`.`quantity` end)) AS `Mar`,sum((case when (`a`.`dat` = 'April') then `a`.`quantity` end)) AS `Apr`,sum((case when (`a`.`dat` = 'May') then `a`.`quantity` end)) AS `May`,sum((case when (`a`.`dat` = 'June') then `a`.`quantity` end)) AS `Jun`,sum((case when (`a`.`dat` = 'July') then `a`.`quantity` end)) AS `Jul`,sum((case when (`a`.`dat` = 'August') then `a`.`quantity` end)) AS `Aug`,sum((case when (`a`.`dat` = 'September') then `a`.`quantity` end)) AS `Sep`,sum((case when (`a`.`dat` = 'October') then `a`.`quantity` end)) AS `Oct`,sum((case when (`a`.`dat` = 'November') then `a`.`quantity` end)) AS `Nov`,sum((case when (`a`.`dat` = 'December') then `a`.`quantity` end)) AS `Dece`,sum((case when (`a`.`dat` = (((((((((('January' + 'February') + 'March') + 'April') + 'May') + 'June') + 'July') + 'August\'September') + 'October') + 'November') + 'December')) then `a`.`quantity` end)) AS `total` from (select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,monthname(`vowsls`.`scm_issue_hdr`.`issue_date`) AS `dat`,concat(`vowsls`.`scm_issue_hdr`.`group_code`,`vowsls`.`scm_issue_hdr`.`item_code`) AS `Itemcode`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_qty`),0) AS `quantity`,`vowsls`.`itemmaster`.`item_desc` AS `Description`,`vowsls`.`scm_issue_hdr`.`uom_code` AS `unit` from (`vowsls`.`scm_issue_hdr` join `vowsls`.`itemmaster` on(((`vowsls`.`scm_issue_hdr`.`company_id` = `vowsls`.`itemmaster`.`company_id`) and (`vowsls`.`scm_issue_hdr`.`item_code` = `vowsls`.`itemmaster`.`item_code`) and (`vowsls`.`scm_issue_hdr`.`group_code` = `vowsls`.`itemmaster`.`group_code`)))) group by `vowsls`.`scm_issue_hdr`.`company_id`,`ac_year`,`dat`,`Description`,`unit`,`Itemcode`) `a` group by `a`.`company_id`,`a`.`ac_year`,`a`.`dat`,`a`.`Description`,`a`.`unit`,`a`.`Itemcode`;;
CREATE OR REPLACE VIEW Store_Quality_Value_Consumption AS select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,concat(`vowsls`.`scm_issue_hdr`.`group_code`,`vowsls`.`scm_issue_hdr`.`item_code`) AS `Itemcode`,`vowsls`.`itemmaster`.`item_desc` AS `Itemdescription`,`vowsls`.`scm_issue_hdr`.`uom_code` AS `Unit`,`vowsls`.`scm_indent_type_master`.`indent_type_desc` AS `Exeptype`,`vowsls`.`master_department`.`dept_desc` AS `Deptdesc`,`vowsls`.`costmaster`.`cost_desc` AS `Costdec`,extract(year_month from `vowsls`.`scm_issue_hdr`.`issue_date`) AS `Month`,monthname(`vowsls`.`scm_issue_hdr`.`issue_date`) AS `Mname`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_qty`),0) AS `Quantity`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),0) AS `Value`,`vowsls`.`item_group_master`.`group_desc` AS `Groupdesc`,round(avg(`vowsls`.`scm_issue_hdr`.`issue_qty`),0) AS `Avgqty`,round(sum((`vowsls`.`scm_issue_hdr`.`issue_value` / `vowsls`.`scm_issue_hdr`.`issue_qty`)),0) AS `Rate` from (((((`vowsls`.`scm_issue_hdr` join `vowsls`.`itemmaster` on(((`vowsls`.`scm_issue_hdr`.`item_code` = `vowsls`.`itemmaster`.`item_code`) and (`vowsls`.`scm_issue_hdr`.`company_id` = `vowsls`.`itemmaster`.`company_id`)))) join `vowsls`.`scm_indent_type_master` on(((`vowsls`.`scm_indent_type_master`.`indent_type_code` = `vowsls`.`scm_issue_hdr`.`indent_type_id`) and (`vowsls`.`scm_indent_type_master`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`)))) join `vowsls`.`master_department` on(((`vowsls`.`master_department`.`mdept_id` = `vowsls`.`scm_issue_hdr`.`dept_id`) and (`vowsls`.`master_department`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`)))) join `vowsls`.`costmaster` on(((`vowsls`.`costmaster`.`dept_code` = `vowsls`.`scm_issue_hdr`.`deptcost`) and (`vowsls`.`costmaster`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`)))) join `vowsls`.`item_group_master` on(((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_issue_hdr`.`group_code`) and (`vowsls`.`item_group_master`.`company_id` = `vowsls`.`scm_issue_hdr`.`company_id`)))) group by `vowsls`.`scm_issue_hdr`.`company_id`,`ac_year`,`Itemcode`,`Itemdescription`,`Unit`,`Exeptype`,`Deptdesc`,`Costdec`,`Groupdesc`,`Month`,`Mname`;;
CREATE OR REPLACE VIEW Store_Stock_Report AS select `a`.`company_id` AS `company_id`,`a`.`Project` AS `Project`,`a`.`Phase` AS `Phase`,`a`.`item_grp_id` AS `item_grp_id`,`a`.`item_code` AS `item_code`,`a`.`itemuniqueno` AS `itemuniqueno`,`a`.`Item_group_description` AS `Item_group_description`,`a`.`item_desc` AS `item_desc`,`a`.`stockbal` AS `stockbal`,`a`.`uom_code` AS `uom_code`,round((`a`.`stockvalue` / `a`.`stockbal`),0) AS `Stock Value Per Unit`,`a`.`stockvalue` AS `stockvalue`,`a`.`lastreceipt` AS `lastreceipt` from (select `h`.`company_id` AS `company_id`,`branch`.`branch_name` AS `Project`,`p`.`prj_name` AS `Phase`,`l`.`item_grp_id` AS `item_grp_id`,`l`.`item_code` AS `item_code`,concat(`l`.`item_grp_id`,`l`.`item_code`) AS `itemuniqueno`,`g`.`group_desc` AS `Item_group_description`,`i`.`item_desc` AS `item_desc`,round(sum(((`l`.`final_qty` - `l`.`quantity_consumed`) - `l`.`stock_transer_quantity`)),3) AS `stockbal`,`i`.`uom_code` AS `uom_code`,round(sum((`l`.`rate` * ((`l`.`final_qty` - `l`.`quantity_consumed`) - `l`.`stock_transer_quantity`))),3) AS `stockvalue`,max(`h`.`store_receive_dt`) AS `lastreceipt` from (((((`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h` on(((`h`.`store_receive_no` = `l`.`store_receive_no`) and (`h`.`sr_good_recept_status` <> 4) and (`h`.`sr_good_recept_status` <> 6) and (((`l`.`final_qty` - `l`.`quantity_consumed`) - `l`.`stock_transer_quantity`) >= 0)))) join `vowsls`.`item_group_master` `g` on(((`l`.`item_grp_id` = `g`.`group_code`) and (`h`.`company_id` = `g`.`company_id`)))) join `vowsls`.`branch_master` `branch` on((`branch`.`branch_id` = `h`.`branch_id`))) left join `vowsls`.`project_master` `p` on((`p`.`prj_id` = `h`.`project_id`))) join `vowsls`.`itemmaster` `i` on(((`l`.`item_grp_id` = `i`.`group_code`) and (`l`.`item_code` = `i`.`item_code`) and (`h`.`company_id` = `i`.`company_id`)))) group by `h`.`company_id`,`Project`,`Phase`,`l`.`item_grp_id`,`l`.`item_code`,`g`.`group_desc`,`i`.`item_desc`,`i`.`uom_code` order by `l`.`item_grp_id`,`l`.`item_code`) `a`;;
CREATE OR REPLACE VIEW Store_Stock_ST18D AS select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,concat(`vowsls`.`scm_sr_line_item`.`item_grp_id`,`vowsls`.`scm_sr_line_item`.`item_code`) AS `ItemCode`,`vowsls`.`itemmaster`.`item_desc` AS `Description`,`vowsls`.`scm_sr_line_item`.`uom_code` AS `Unit`,sum(`vowsls`.`scm_sr_line_item`.`final_qty`) AS `Quantity`,cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date) AS `Date`,max(`vowsls`.`itemmaster`.`max_value`) AS `maxqty`,min(`vowsls`.`itemmaster`.`max_order_value`) AS `minqty`,round(`vowsls`.`scm_sr_line_item`.`rate`,0) AS `Rate`,`vowsls`.`suppliermaster`.`supp_name` AS `Supplier` from (((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_sr_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`)))) join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`scm_sr_hdr`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`ItemCode`,`vowsls`.`itemmaster`.`item_desc`,`Unit`,`Date`,`Supplier`,`vowsls`.`scm_sr_line_item`.`rate`;;
CREATE OR REPLACE VIEW Store_consumption_IS03 AS select `a`.`company_id` AS `company_id`,`a`.`date` AS `date`,`a`.`DEPARTMENT` AS `DEPARTMENT`,`a`.`general` AS `general`,`a`.`overhauling` AS `overhauling`,`a`.`Maintainence` AS `Maintainence`,`a`.`capital` AS `capital`,`a`.`production` AS `production`,((((`a`.`production` + `a`.`general`) + `a`.`overhauling`) + `a`.`Maintainence`) + `a`.`capital`) AS `Total Cost` from (select `i`.`company_id` AS `company_id`,`i`.`issue_date` AS `date`,`md`.`dept_desc` AS `DEPARTMENT`,round(sum((case when (`i`.`indent_type_id` = 'G') then `i`.`issue_value` else 0 end)),1) AS `general`,round(sum((case when (`i`.`indent_type_id` = 'H') then `i`.`issue_value` else 0 end)),1) AS `overhauling`,round(sum((case when (`i`.`indent_type_id` = 'M') then `i`.`issue_value` else 0 end)),1) AS `Maintainence`,round(sum((case when (`i`.`indent_type_id` = 'P') then `i`.`issue_value` else 0 end)),1) AS `production`,sum((case when (`i`.`indent_type_id` = 'C') then `i`.`issue_value` else 0 end)) AS `capital` from (`vowsls`.`scm_issue_hdr` `i` join `vowsls`.`master_department` `md` on(((`i`.`company_id` = `md`.`company_id`) and (`i`.`dept_id` = `md`.`mdept_id`)))) group by `i`.`company_id`,`date`,`DEPARTMENT`) `a`;;
CREATE OR REPLACE VIEW Store_consumption_IS15 AS select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,concat(`vowsls`.`scm_sr_line_item`.`is_active`,`vowsls`.`scm_sr_line_item`.`item_code`) AS `itemcode`,`vowsls`.`itemmaster`.`item_desc` AS `Description`,`vowsls`.`scm_sr_line_item`.`uom_code` AS `Unit`,cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date) AS `srdate`,round(sum(`vowsls`.`scm_sr_line_item`.`final_qty`),0) AS `Quantity`,round(sum(`vowsls`.`scm_sr_line_item`.`final_value`),0) AS `Value`,round(avg(`vowsls`.`scm_sr_line_item`.`final_qty`),0) AS `avgq`,round(avg(`vowsls`.`scm_sr_line_item`.`final_value`),0) AS `avgf` from ((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`itemmaster` on(((`vowsls`.`scm_sr_line_item`.`item_grp_id` = `vowsls`.`itemmaster`.`group_code`) and (`vowsls`.`scm_sr_line_item`.`item_code` = `vowsls`.`itemmaster`.`item_code`)))) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`itemcode`,`vowsls`.`itemmaster`.`item_desc`,`Unit`,`srdate`;;
CREATE OR REPLACE VIEW Store_consumption_IS18 AS select `a`.`company_id` AS `company_id`,`a`.`ac_year` AS `ac_year`,`a`.`Itemcode` AS `Itemcode`,`a`.`Value` AS `Value`,`a`.`Description` AS `Description`,`a`.`unit` AS `unit`,sum((case when (`a`.`dat` = 'January') then `a`.`Value` else '0' end)) AS `Jan`,sum((case when (`a`.`dat` = 'February') then `a`.`Value` else '0' end)) AS `Feb`,sum((case when (`a`.`dat` = 'March') then `a`.`Value` else '0' end)) AS `Mar`,sum((case when (`a`.`dat` = 'April') then `a`.`Value` else '0' end)) AS `Apr`,sum((case when (`a`.`dat` = 'May') then `a`.`Value` else '0' end)) AS `May`,sum((case when (`a`.`dat` = 'June') then `a`.`Value` else '0' end)) AS `Jun`,sum((case when (`a`.`dat` = 'July') then `a`.`Value` else '0' end)) AS `Jul`,sum((case when (`a`.`dat` = 'August') then `a`.`Value` else '0' end)) AS `Aug`,sum((case when (`a`.`dat` = 'September') then `a`.`Value` else '0' end)) AS `Sep`,sum((case when (`a`.`dat` = 'October') then `a`.`Value` else '0' end)) AS `Oct`,sum((case when (`a`.`dat` = 'November') then `a`.`Value` else '0' end)) AS `Nov`,sum((case when (`a`.`dat` = 'December') then `a`.`Value` else '0' end)) AS `Dece`,sum((case when (`a`.`dat` = (((((((((('January' + 'February') + 'March') + 'April') + 'May') + 'June') + 'July') + 'August\'September') + 'October') + 'November') + 'December')) then `a`.`Value` end)) AS `total` from (select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,monthname(`vowsls`.`scm_issue_hdr`.`issue_date`) AS `dat`,concat(`vowsls`.`scm_issue_hdr`.`group_code`,`vowsls`.`scm_issue_hdr`.`item_code`) AS `Itemcode`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),0) AS `Value`,`vowsls`.`itemmaster`.`item_desc` AS `Description`,`vowsls`.`scm_issue_hdr`.`uom_code` AS `unit` from (`vowsls`.`scm_issue_hdr` join `vowsls`.`itemmaster` on(((`vowsls`.`scm_issue_hdr`.`company_id` = `vowsls`.`itemmaster`.`company_id`) and (`vowsls`.`scm_issue_hdr`.`item_code` = `vowsls`.`itemmaster`.`item_code`) and (`vowsls`.`scm_issue_hdr`.`group_code` = `vowsls`.`itemmaster`.`group_code`)))) group by `vowsls`.`scm_issue_hdr`.`company_id`,`ac_year`,`dat`,`Description`,`unit`,`Itemcode`) `a` group by `a`.`company_id`,`a`.`ac_year`,`a`.`dat`,`a`.`Description`,`a`.`unit`,`a`.`Itemcode`;;
CREATE OR REPLACE VIEW Store_consumption_IS19 AS select `vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,`vowsls`.`itemmaster`.`item_desc` AS `itemdescription`,`vowsls`.`scm_issue_hdr`.`issue_date` AS `issuedate`,extract(year_month from `vowsls`.`scm_issue_hdr`.`issue_date`) AS `date`,monthname(`vowsls`.`scm_issue_hdr`.`issue_date`) AS `montnam`,`vowsls`.`scm_issue_hdr`.`uom_code` AS `uom`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_qty`),0) AS `TotalQuantity`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),0) AS `TotalValue` from (`vowsls`.`scm_issue_hdr` join `vowsls`.`itemmaster` on(((`vowsls`.`scm_issue_hdr`.`item_code` = `vowsls`.`itemmaster`.`item_code`) and (0 <> `vowsls`.`scm_issue_hdr`.`group_code`) and (`vowsls`.`scm_issue_hdr`.`company_id` = `vowsls`.`itemmaster`.`item_code`)))) group by `vowsls`.`scm_issue_hdr`.`company_id`,`ac_year`,`itemdescription`,`montnam`,`uom`,`date`,`issuedate` order by `montnam`,`date`;;
CREATE OR REPLACE VIEW Store_low_stock_items_with_qty AS select `a`.`company_id` AS `company_id`,`a`.`ac_year` AS `ac_year`,`a`.`itemcode` AS `itemcode`,`a`.`itemname` AS `itemname`,`a`.`minqty` AS `minqty`,`a`.`currentstock` AS `currentstock`,`a`.`indentqty` AS `indentqty`,`a`.`poquantity` AS `poquantity`,`a`.`inspectionqty` AS `inspectionqty`,(((`a`.`currentstock` + `a`.`indentqty`) + `a`.`poquantity`) + `a`.`inspectionqty`) AS `total` from (select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,concat(`vowsls`.`scm_sr_line_item`.`item_grp_id`,`vowsls`.`scm_sr_line_item`.`item_code`) AS `itemcode`,`vowsls`.`itemmaster`.`item_desc` AS `itemname`,`vowsls`.`itemmaster`.`max_order_value` AS `minqty`,ifnull(sum((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_sr_line_item`.`quantity_consumed`)),0) AS `currentstock`,round(sum(`vowsls`.`scm_indent_line_item`.`indent_qty`),0) AS `indentqty`,round(sum(`vowsls`.`scm_po_line_item`.`quantity`),0) AS `poquantity`,round(sum(`vowsls`.`gate_store_entry_reg_dtl`.`quantity`),0) AS `inspectionqty` from (((((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`) and (`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_sr_line_item`.`item_code`)))) join `vowsls`.`scm_indent_line_item` on(((`vowsls`.`scm_indent_line_item`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`) and (`vowsls`.`scm_indent_line_item`.`item_code` = `vowsls`.`scm_sr_line_item`.`item_code`)))) join `vowsls`.`scm_po_line_item` on((`vowsls`.`scm_po_line_item`.`i_tax` = `vowsls`.`scm_indent_line_item`.`indent_srl_no`))) join `vowsls`.`gate_store_entry_reg_dtl` on((`vowsls`.`gate_store_entry_reg_dtl`.`po_line_no` = `vowsls`.`scm_po_line_item`.`line_item_num`))) where (`vowsls`.`itemmaster`.`max_order_value` > '0') group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`itemcode`,`itemname`,`minqty`) `a`;;
CREATE OR REPLACE VIEW Store_stock_ST18A AS select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,concat(`vowsls`.`scm_sr_line_item`.`item_grp_id`,`vowsls`.`scm_sr_line_item`.`item_code`) AS `ItemCode`,`vowsls`.`itemmaster`.`item_desc` AS `Description`,`vowsls`.`scm_sr_line_item`.`uom_code` AS `Unit`,`vowsls`.`scm_sr_line_item`.`final_qty` AS `Quantity`,cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date) AS `Date`,round(max(`vowsls`.`scm_sr_line_item`.`final_qty`),0) AS `Maximumquantity`,round(min(`vowsls`.`scm_sr_line_item`.`final_qty`),0) AS `Minimumquantity`,round(`vowsls`.`scm_sr_line_item`.`rate`,0) AS `Rate`,`vowsls`.`suppliermaster`.`supp_name` AS `Supplier` from (((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_sr_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`)))) join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`scm_sr_hdr`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`ItemCode`,`vowsls`.`itemmaster`.`item_desc`,`Unit`,`Date`,`Supplier`,`vowsls`.`scm_sr_line_item`.`rate`,`Quantity` order by `Date`;;
CREATE OR REPLACE VIEW Store_stock_st18B AS select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,concat(`vowsls`.`scm_sr_line_item`.`item_grp_id`,`vowsls`.`scm_sr_line_item`.`item_code`) AS `ItemCode`,`vowsls`.`itemmaster`.`item_desc` AS `Description`,`vowsls`.`scm_sr_line_item`.`uom_code` AS `Unit`,`vowsls`.`scm_sr_line_item`.`final_qty` AS `Quantity`,cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date) AS `Date`,week(cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date),0) AS `week`,round(max(`vowsls`.`scm_sr_line_item`.`final_qty`),0) AS `Maximumquantity`,round(min(`vowsls`.`scm_sr_line_item`.`final_qty`),0) AS `Minimumquantity`,round(`vowsls`.`scm_sr_line_item`.`rate`,0) AS `Rate`,`vowsls`.`suppliermaster`.`supp_name` AS `Supplier` from (((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_sr_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`)))) join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`scm_sr_hdr`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`ItemCode`,`vowsls`.`itemmaster`.`item_desc`,`Unit`,`Date`,`Supplier`,`vowsls`.`scm_sr_line_item`.`rate`,`Quantity`,`week` order by `week`;;
CREATE OR REPLACE VIEW View_Employee_inleave_list AS select `l`.`company_id` AS `company_id`,`l`.`eb_id` AS `Employee_Id`,`w`.`worker_name` AS `Employee_Name`,`l`.`leave_to_date` AS `In_Leave`,`lt`.`leave_type_description` AS `Leave_Type` from ((`vowsls`.`leave_transactions` `l` join `vowsls`.`worker_master` `w` on((`w`.`eb_id` = `l`.`eb_id`))) join `vowsls`.`leave_types` `lt` on((`lt`.`leave_type_id` = `l`.`leave_type_id`))) where (`l`.`leave_to_date` >= curdate());;
CREATE OR REPLACE VIEW allcompany_Month_Wise_Store_Consumption_Widgets AS select `vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),0) AS `value`,monthname(`vowsls`.`scm_issue_hdr`.`issue_date`) AS `mon`,extract(year_month from `vowsls`.`scm_issue_hdr`.`issue_date`) AS `montnme`,'consumption' AS `storepurchase` from `vowsls`.`scm_issue_hdr` group by `ac_year`,`montnme`,`mon` order by `montnme`;;
CREATE OR REPLACE VIEW allcompany_Pending_Delivery_Widget AS select `p`.`po_date` AS `Po Date`,`p`.`po_num` AS `Po No`,`s`.`supp_name` AS `Supplier`,`i`.`item_desc` AS `Item Name`,(`l`.`quantity` - `l`.`gate_po_placed`) AS `Quantity`,round(sum(((`l`.`quantity` - `l`.`gate_po_placed`) * `l`.`rate`)),0) AS `value`,(to_days(curdate()) - to_days(`p`.`expected_date`)) AS `Due Days`,`p`.`fin_year` AS `ac_year` from (((`vowsls`.`scm_po_hdr` `p` join `vowsls`.`scm_po_line_item` `l`) join `vowsls`.`suppliermaster` `s`) join `vowsls`.`itemmaster` `i`) where ((`p`.`po_num` = `l`.`po_num`) and ((`l`.`quantity` - `l`.`gate_po_placed`) > 0) and (cast(curdate() as date) > `p`.`expected_date`) and (`p`.`po_type` <> 'J') and (`s`.`supp_code` = `p`.`supp_code`) and (`l`.`item_code` = `i`.`item_code`) and (`l`.`group_code` = `i`.`group_code`) and (`p`.`po_status` = 3)) group by `p`.`po_date`,`p`.`po_num`,`s`.`supp_name`,`p`.`fin_year`,`p`.`expected_date`,`i`.`item_desc`,(`l`.`quantity` - `l`.`gate_po_placed`) order by `Due Days` desc;;
CREATE OR REPLACE VIEW allcompany_month_wise_purchase AS select `vowsls`.`scm_po_hdr`.`fin_year` AS `ac_year`,extract(year_month from `vowsls`.`scm_po_hdr`.`po_date`) AS `pomonth`,monthname(`vowsls`.`scm_po_hdr`.`po_date`) AS `month`,round(sum(`vowsls`.`scm_po_hdr`.`po_val_wt_tax`),0) AS `amount`,'purchase' AS `salepurchase` from `vowsls`.`scm_po_hdr` group by `pomonth`,`month`,`ac_year` order by `pomonth` limit 24;;
CREATE OR REPLACE VIEW allcompany_payments_due AS select `h`.`ac_year` AS `ac_year`,'total' AS `total`,round(sum(`l`.`amount_with_tax`),0) AS `Supplied`,(select round(sum(`vowsls`.`bill_pass`.`net_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`) and (`vowsls`.`bill_pass`.`bill_type` = 'S'))) AS `billpassed`,((select round(sum(`vowsls`.`bill_pass`.`net_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`bill_type` = 'S') and (`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`))) - (select round(sum(`vowsls`.`bill_pass`.`due_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`bill_type` = 'S') and (`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`)))) AS `PaidAmount`,(select round(sum(`vowsls`.`bill_pass`.`due_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`) and (`vowsls`.`bill_pass`.`bill_type` = 'S'))) AS `Due` from (`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h`) where ((`l`.`store_receive_no` = `h`.`store_receive_no`) and (`l`.`is_active` = 1)) group by `h`.`ac_year`;;
CREATE OR REPLACE VIEW allcompany_pending_po AS select cast(`p`.`indent_date` as date) AS `Indent Date`,`p`.`indent_no` AS `Indent No`,`i`.`item_desc` AS `Item Name`,sum(round((`l`.`indent_qty` - `l`.`po_placed`),3)) AS `Quantity`,`l`.`item_code` AS `item_code`,(to_days(curdate()) - to_days(`p`.`indent_date`)) AS `Due Days`,`p`.`company_id` AS `company_id`,`cm`.`company_code` AS `City`,`p`.`fin_year` AS `ac_year` from (((`vowsls`.`scm_indent_hdr` `p` join `vowsls`.`scm_indent_line_item` `l`) join `vowsls`.`itemmaster` `i`) join `vowsls`.`company_master` `cm`) where ((`p`.`indent_no` = `l`.`indent_no`) and (cast(curdate() as date) > `p`.`indent_date`) and (`p`.`indent_type` <> 'J') and (`l`.`item_code` = `i`.`item_code`) and (`l`.`is_active` = 1) and (`l`.`group_code` = `i`.`group_code`) and (`p`.`company_id` = `i`.`company_id`) and (`p`.`indent_status` = 3) and (`p`.`company_id` = `l`.`company_id`) and (`p`.`indent_no` = `l`.`indent_no`) and (`p`.`fin_year` = `l`.`fin_year`) and (`p`.`company_id` = `cm`.`comp_id`) and (round((`l`.`indent_qty` - `l`.`po_placed`),3) > 0)) group by `p`.`indent_date`,`p`.`indent_no`,`p`.`company_id`,`p`.`fin_year`,`i`.`item_desc`,`l`.`item_code` order by `Due Days` desc;;
CREATE OR REPLACE VIEW allcompany_view_store_consumption_categoryWise AS select `a`.`ac_year` AS `ac_year`,`a`.`opening` AS `opening`,`a`.`Transferred` AS `Transferred`,`a`.`itemgroup` AS `itemgroup`,`a`.`issuevalue` AS `issuevalue`,`a`.`returnvalue` AS `returnvalue`,(((`a`.`opening` + `a`.`returnvalue`) - `a`.`issuevalue`) - `a`.`Transferred`) AS `closingvalue` from (select `vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,round(sum((((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_sr_line_item`.`stock_transer_quantity`) - `vowsls`.`scm_sr_line_item`.`quantity_consumed`) * `vowsls`.`scm_sr_line_item`.`rate`)),2) AS `opening`,round(sum((`vowsls`.`scm_sr_line_item`.`stock_transer_quantity` * `vowsls`.`scm_sr_line_item`.`rate`)),0) AS `Transferred`,`vowsls`.`item_group_master`.`group_code` AS `itemgroup`,round(sum(ifnull(`vowsls`.`scm_issue_hdr`.`issue_value`,0)),0) AS `issuevalue`,round(sum(ifnull((`vowsls`.`scm_return_hdr`.`return_qty` * `vowsls`.`scm_return_hdr`.`return_rate`),0)),0) AS `returnvalue` from ((((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`item_group_master` on((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`))) left join `vowsls`.`scm_issue_hdr` on(((`vowsls`.`scm_issue_hdr`.`sr_line_id` = `vowsls`.`scm_sr_line_item`.`store_line_item_no`) and (`vowsls`.`scm_sr_line_item`.`is_active` = 1) and (`vowsls`.`scm_issue_hdr`.`is_active` = 1)))) left join `vowsls`.`scm_return_hdr` on((`vowsls`.`scm_return_hdr`.`issue_rec_id` = `vowsls`.`scm_issue_hdr`.`issue_no`))) where (((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_sr_line_item`.`stock_transer_quantity`) - `vowsls`.`scm_sr_line_item`.`quantity_consumed`) > 0) group by `vowsls`.`scm_sr_hdr`.`ac_year`,`itemgroup` order by `itemgroup`) `a`;;
CREATE OR REPLACE VIEW allcompany_view_store_stock_inventory_category_wise AS select `a`.`opening` AS `opening`,`a`.`receivedvalue` AS `receivedvalue`,`a`.`pending` AS `pending`,`a`.`itemgroup` AS `itemgroup`,`a`.`poplaced` AS `poplaced`,((`a`.`opening` + `a`.`receivedvalue`) - `a`.`pending`) AS `finalstock`,`a`.`indent` AS `indent` from (select round(sum((((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_sr_line_item`.`stock_transer_quantity`) - `vowsls`.`scm_sr_line_item`.`quantity_consumed`) * `vowsls`.`scm_sr_line_item`.`rate`)),2) AS `opening`,round(sum((`vowsls`.`scm_sr_line_item`.`final_qty` * `vowsls`.`scm_sr_line_item`.`rate`)),0) AS `receivedvalue`,round(sum(((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_sr_line_item`.`quantity_consumed`) * `vowsls`.`scm_sr_line_item`.`rate`)),0) AS `pending`,`vowsls`.`item_group_master`.`group_code` AS `itemgroup`,round(sum(((`vowsls`.`scm_po_line_item`.`quantity` - `vowsls`.`scm_po_line_item`.`gate_po_placed`) * `vowsls`.`scm_po_line_item`.`rate`)),0) AS `poplaced`,round(sum(((`vowsls`.`scm_indent_line_item`.`indent_qty` - `vowsls`.`scm_indent_line_item`.`po_placed`) * `vowsls`.`scm_indent_line_item`.`rate`)),0) AS `indent` from (((((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`item_group_master` on((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`))) join `vowsls`.`gate_store_entry_reg_dtl` on((`vowsls`.`gate_store_entry_reg_dtl`.`dtl_id` = `vowsls`.`scm_sr_line_item`.`gate_line_item_no`))) join `vowsls`.`scm_po_line_item` on((`vowsls`.`scm_po_line_item`.`line_item_num` = `vowsls`.`gate_store_entry_reg_dtl`.`dtl_id`))) join `vowsls`.`scm_indent_line_item` on((`vowsls`.`scm_indent_line_item`.`indent_srl_no` = `vowsls`.`scm_po_line_item`.`indent_no`))) group by `itemgroup` order by `itemgroup`) `a`;;
CREATE OR REPLACE VIEW allcompany_view_store_stock_summary_values AS select (select ((round(sum((`srl`.`final_qty` * `srl`.`rate`)),0) - round(sum((`srl`.`quantity_consumed` * `srl`.`rate`)),0)) - round(sum((`srl`.`stock_transer_quantity` * `srl`.`rate`)),0)) AS `open` from (`vowsls`.`scm_sr_line_item` `srl` join `vowsls`.`scm_sr_hdr` `srh`) where ((`srh`.`store_receive_no` = `srl`.`store_receive_no`) and (month(curdate()) < month(`srh`.`store_receive_dt`)) and (year(`srh`.`store_receive_dt`) < year(curdate())) and (`srl`.`is_active` = 1))) AS `Open`,(select round(sum(((`l`.`indent_qty` - `l`.`po_placed`) * `l`.`rate`)),0) from `vowsls`.`scm_indent_line_item` `l` where ((`l`.`indent_type` <> 'J') and (`l`.`is_active` = 1))) AS `Indent`,(select round(sum(((`pl`.`quantity` - `pl`.`gate_po_placed`) * `pl`.`rate`)),0) from (`vowsls`.`scm_po_line_item` `pl` join `vowsls`.`scm_po_hdr` `p`) where ((`p`.`po_num` = `pl`.`po_num`) and (`pl`.`is_active` = 1) and (`p`.`po_type` <> 'J'))) AS `Po`,round(sum((`sl`.`final_qty` * `sl`.`rate`)),0) AS `Receipt`,round(sum((`sl`.`quantity_consumed` * `sl`.`rate`)),0) AS `Issue`,round(sum((`sl`.`stock_transer_quantity` * `sl`.`rate`)),0) AS `Transfer`,((select ((round(sum((`srl`.`final_qty` * `srl`.`rate`)),0) - round(sum((`srl`.`quantity_consumed` * `srl`.`rate`)),0)) - round(sum((`srl`.`stock_transer_quantity` * `srl`.`rate`)),0)) AS `open` from (`vowsls`.`scm_sr_line_item` `srl` join `vowsls`.`scm_sr_hdr` `srh`) where ((`srh`.`store_receive_no` = `srl`.`store_receive_no`) and (month(curdate()) < month(`srh`.`store_receive_dt`)) and (year(`srh`.`store_receive_dt`) < year(curdate())) and (`srl`.`is_active` = 1))) + round(((sum((`sl`.`final_qty` * `sl`.`rate`)) - sum((`sl`.`quantity_consumed` * `sl`.`rate`))) - sum((`sl`.`stock_transer_quantity` * `sl`.`rate`))),0)) AS `Final` from (`vowsls`.`scm_sr_line_item` `sl` join `vowsls`.`scm_sr_hdr` `sh` on(((`sh`.`store_receive_no` = `sl`.`store_receive_no`) and (month(`sh`.`store_receive_dt`) = month(curdate())) and (year(`sh`.`store_receive_dt`) = year(curdate())))));;
CREATE OR REPLACE VIEW allcompany_view_store_summary_value_wid AS select `b`.`disp_order` AS `disp_order`,`b`.`order` AS `order`,`b`.`word` AS `word`,`b`.`val` AS `val` from (select 'Open' AS `disp_order`,'1' AS `order`,'Open' AS `word`,`vowsls`.`allcompany_view_store_stock_summary_values`.`Open` AS `val` from `vowsls`.`allcompany_view_store_stock_summary_values` union select 'Indent' AS `disp_order`,'2' AS `order`,'Indent' AS `word`,`vowsls`.`allcompany_view_store_stock_summary_values`.`Indent` AS `val` from `vowsls`.`allcompany_view_store_stock_summary_values` union select 'PO' AS `disp_order`,'3' AS `order`,'PO' AS `word`,`vowsls`.`allcompany_view_store_stock_summary_values`.`Po` AS `val` from `vowsls`.`allcompany_view_store_stock_summary_values` union select 'Receipt' AS `disp_order`,'4' AS `order`,'Receipt' AS `word`,`vowsls`.`allcompany_view_store_stock_summary_values`.`Receipt` AS `val` from `vowsls`.`allcompany_view_store_stock_summary_values` union select 'Issue' AS `disp_order`,'5' AS `order`,'Issue' AS `word`,`vowsls`.`allcompany_view_store_stock_summary_values`.`Issue` AS `val` from `vowsls`.`allcompany_view_store_stock_summary_values` union select 'Transfer' AS `disp_order`,'6' AS `order`,'Transfer' AS `word`,`vowsls`.`allcompany_view_store_stock_summary_values`.`Transfer` AS `val` from `vowsls`.`allcompany_view_store_stock_summary_values` union select 'Final' AS `disp_order`,'7' AS `order`,'Final' AS `word`,`vowsls`.`allcompany_view_store_stock_summary_values`.`Final` AS `val` from `vowsls`.`allcompany_view_store_stock_summary_values`) `b` order by `b`.`order`;;
CREATE OR REPLACE VIEW bill_hdr_view AS select `p`.`company_id` AS `company_id`,`l`.`store_line_item_no` AS `Line item no`,`cm`.`company_name` AS `Company Name`,`p`.`branch_id` AS `Branch Id`,`bm`.`branch_name` AS `Branch Name`,`p`.`project_id` AS `Project Id`,`pm`.`prj_name` AS `Project Name`,`p`.`fin_year` AS `Ac Year`,`p`.`bill_pass_trans_no` AS `bill_no`,`p`.`invoice_amount` AS `invoice_amount`,`p`.`invoice_date` AS `invoice_date`,`p`.`invoice_recieved_date` AS `invoice_recieved_date`,`p`.`invoice_no` AS `invoice_no`,`p`.`net_amount` AS `Amount`,`p`.`due_amount` AS `Due Amount`,`p`.`bill_date` AS `Bill_Date`,`p`.`sr_mr_num` AS `Sr No`,`su`.`supp_code` AS `Supp Code`,`su`.`supp_name` AS `Supplier`,`p`.`status` AS `Status Id`,`sm`.`status_name` AS `status_name`,`l`.`item_grp_id` AS `Group Code`,`igm`.`group_desc` AS `Group Name`,`im`.`item_code` AS `Item Code`,`im`.`item_desc` AS `Item Desc`,`l`.`c_tax` AS `C Tax`,`l`.`s_tax` AS `S Tax`,`l`.`i_tax` AS `I Tax`,`l`.`final_qty` AS `Sr Quantity`,`l`.`rate` AS `Master Rate` from (((((((((`vowsls`.`bill_pass` `p` join `vowsls`.`scm_sr_hdr` `b` on(((`p`.`sr_mr_num` = `b`.`store_receive_no`) and (`b`.`sr_type` = 'SR')))) join `vowsls`.`scm_sr_line_item` `l` on(((`l`.`store_receive_no` = `b`.`store_receive_no`) and (`l`.`is_active` = 1)))) left join `vowsls`.`company_master` `cm` on((`cm`.`comp_id` = `p`.`company_id`))) left join `vowsls`.`branch_master` `bm` on((`bm`.`branch_id` = `p`.`branch_id`))) left join `vowsls`.`project_master` `pm` on((`pm`.`prj_id` = `p`.`project_id`))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `p`.`status`))) left join `vowsls`.`item_group_master` `igm` on(((`igm`.`group_code` = `l`.`item_grp_id`) and (`p`.`company_id` = `igm`.`company_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`item_code` = `l`.`item_code`) and (`im`.`company_id` = `p`.`company_id`) and (`im`.`group_code` = `l`.`item_grp_id`) and (`im`.`is_active` = 1)))) left join `vowsls`.`suppliermaster` `su` on(((`p`.`supp_code` = `su`.`supp_code`) and (`su`.`company_id` = `p`.`company_id`)))) where (`p`.`bill_type` = 'S');;
CREATE OR REPLACE VIEW both_jute_production_qty AS select `vowsls`.`jute_line_widget`.`monyear` AS `month_year`,`vowsls`.`jute_line_widget`.`monthna` AS `monthname`,`vowsls`.`jute_line_widget`.`juteissue` AS `juteissue`,`vowsls`.`jute_line_widget`.`quantity` AS `Quantity` from `vowsls`.`jute_line_widget` union select `vowsls`.`production_line_graph`.`monthna` AS `month_year`,`vowsls`.`production_line_graph`.`mon` AS `monthname`,`vowsls`.`production_line_graph`.`prodction` AS `Production`,`vowsls`.`production_line_graph`.`productionqty` AS `Production` from `vowsls`.`production_line_graph`;;
CREATE OR REPLACE VIEW branch_wise_stockbal AS select `h`.`company_id` AS `company_id`,`l`.`item_grp_id` AS `item_grp_id`,`l`.`item_code` AS `item_code`,round(sum(((`l`.`final_qty` - `l`.`quantity_consumed`) - `l`.`stock_transer_quantity`)),3) AS `stockbal`,`h`.`branch_id` AS `branch_id` from (`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h`) where ((`h`.`sr_good_recept_status` <> 4) and (`h`.`sr_good_recept_status` <> 6) and (`l`.`is_active` = 1) and (`l`.`store_receive_no` = `h`.`store_receive_no`) and (((`l`.`final_qty` - `l`.`quantity_consumed`) - `l`.`stock_transer_quantity`) > 0)) group by `h`.`company_id`,`l`.`item_grp_id`,`l`.`item_code`,`h`.`branch_id`;;
CREATE OR REPLACE VIEW claim_deviation AS select `smh`.`supp_code` AS `supp_code`,`s`.`supp_name` AS `supp_name`,`smh`.`company_id` AS `company_id`,`smh`.`mr_print_no` AS `mr_print_no`,cast(`smh`.`jute_receive_dt` as date) AS `jute_receive_dt`,`i`.`item_desc` AS `item_desc`,`jqpm`.`jute_quality` AS `jute_quality`,`smli`.`allowable_moisture` AS `allowable_moisture`,`smli`.`claims_condition` AS `claims_condition`,`smli`.`claim_dust` AS `claim_dust`,`smli`.`actual_weight` AS `actual_weight`,(case when ((`smli`.`claims_condition` - `smli`.`allowable_moisture`) > 0) then round((((`smli`.`claims_condition` - `smli`.`allowable_moisture`) + `smli`.`claim_dust`) * `smli`.`actual_weight`),0) else round((`smli`.`claim_dust` * `smli`.`actual_weight`),0) end) AS `actual_shortage`,`smli`.`shortage_kgs` AS `shortage_kgs` from ((((`vowsls`.`scm_mr_line_item` `smli` join `vowsls`.`scm_mr_hdr` `smh` on((`smli`.`jute_receive_no` = `smh`.`jute_receive_no`))) join `vowsls`.`suppliermaster` `s` on(((`s`.`company_id` = `smh`.`company_id`) and (`s`.`supp_code` = `smh`.`supp_code`)))) join `vowsls`.`itemmaster` `i` on(((`i`.`company_id` = `smh`.`company_id`) and (`i`.`group_code` = 999) and (`i`.`item_code` = `smli`.`item_code`)))) join `vowsls`.`jute_quality_price_master` `jqpm` on(((`jqpm`.`company_id` = `smh`.`company_id`) and (`jqpm`.`id` = `smli`.`actual_quality`)))) where (((case when ((`smli`.`claims_condition` - `smli`.`allowable_moisture`) > 0) then round((((`smli`.`claims_condition` - `smli`.`allowable_moisture`) + `smli`.`claim_dust`) * `smli`.`actual_weight`),0) else round((`smli`.`claim_dust` * `smli`.`actual_weight`),0) end) - `smli`.`shortage_kgs`) > 1);;
CREATE OR REPLACE VIEW date_wise_suplyr_report AS select `a`.`company_id` AS `company_id`,`a`.`ac_year` AS `ac_year`,`a`.`srno` AS `srno`,`a`.`supplierinvoiceno` AS `supplierinvoiceno`,`a`.`suppliername` AS `suppliername`,`a`.`date` AS `date`,`a`.`Itemdescription` AS `Itemdescription`,`a`.`qty` AS `qty`,`a`.`unit` AS `unit`,`a`.`Rate` AS `Rate`,`a`.`Totalvalue` AS `Totalvalue`,`a`.`cgst` AS `cgst`,`a`.`sgst` AS `sgst`,((`a`.`Totalvalue` + `a`.`cgst`) + `a`.`sgst`) AS `netsrvalue` from (select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,`vowsls`.`scm_sr_hdr`.`store_receipt_no` AS `srno`,cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date) AS `date`,`vowsls`.`scm_sr_line_item`.`rate` AS `Rate`,`vowsls`.`scm_sr_line_item`.`uom_code` AS `unit`,round(sum(`vowsls`.`scm_sr_line_item`.`final_qty`),1) AS `qty`,round(sum(`vowsls`.`scm_sr_line_item`.`final_value`),1) AS `Totalvalue`,sum(ifnull(`vowsls`.`scm_sr_line_item`.`c_tax`,0)) AS `cgst`,sum(ifnull(`vowsls`.`scm_sr_line_item`.`s_tax`,0)) AS `sgst`,`vowsls`.`itemmaster`.`item_desc` AS `Itemdescription`,`vowsls`.`bill_pass`.`invoice_no` AS `supplierinvoiceno`,`vowsls`.`suppliermaster`.`supp_name` AS `suppliername` from ((((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_sr_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) join `vowsls`.`bill_pass` on(((`vowsls`.`bill_pass`.`sr_mr_num` = `vowsls`.`scm_sr_hdr`.`store_receive_no`) and (`vowsls`.`bill_pass`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`scm_sr_hdr`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`srno`,`date`,`Itemdescription`,`supplierinvoiceno`,`suppliername`,`vowsls`.`scm_sr_line_item`.`rate`,`unit`) `a`;;
CREATE OR REPLACE VIEW datewise_expwise_consumption AS select `i`.`company_id` AS `company_id`,`i`.`issue_date` AS `issue_date`,`i`.`dept_id` AS `dept_id`,`i`.`deptcost` AS `deptcost`,`md`.`dept_desc` AS `DEPARTMENT`,`cm`.`cost_desc` AS `COST CENTER`,round(sum((case when (`i`.`indent_type_id` = 'G') then `i`.`issue_value` else 0 end)),2) AS `general`,round(sum((case when (`i`.`indent_type_id` = 'H') then `i`.`issue_value` else 0 end)),2) AS `overhauling`,round(sum((case when (`i`.`indent_type_id` = 'M') then `i`.`issue_value` else 0 end)),2) AS `maintenance`,round(sum((case when (`i`.`indent_type_id` = 'P') then `i`.`issue_value` else 0 end)),2) AS `production`,round(sum((case when (`i`.`indent_type_id` = 'C') then `i`.`issue_value` else 0 end)),2) AS `capital`,round(sum(`i`.`issue_value`),2) AS `total` from ((`vowsls`.`scm_issue_hdr` `i` join `vowsls`.`master_department` `md`) join `vowsls`.`costmaster` `cm`) where ((`i`.`is_active` = 1) and (`i`.`company_id` = `md`.`company_id`) and (`i`.`dept_id` = `md`.`mdept_id`) and (`i`.`company_id` = `cm`.`company_id`) and (`i`.`deptcost` = `cm`.`id`)) group by `i`.`company_id`,`i`.`issue_date`,`i`.`dept_id`,`i`.`deptcost`,`md`.`dept_desc`,`cm`.`cost_desc` order by `i`.`company_id`,`i`.`issue_date`,`i`.`dept_id`,`i`.`deptcost`;;
CREATE OR REPLACE VIEW duplicate_view AS select `vowsls`.`bill_pass`.`company_id` AS `Company_id`,`vowsls`.`bill_pass`.`fin_year` AS `ac_year`,cast(`vowsls`.`bill_pass`.`bill_date` as date) AS `Billdate`,`vowsls`.`bill_pass`.`bill_no` AS `billno`,`vowsls`.`billpass_line_items`.`description` AS `Description`,`vowsls`.`billpass_line_items`.`uom` AS `Unit`,`vowsls`.`billpass_line_items`.`rate` AS `Rate`,`vowsls`.`bill_pass`.`invoice_no` AS `Invoiceno`,cast(`vowsls`.`bill_pass`.`payment_due_date` as date) AS `paymentduedate`,cast(`vowsls`.`bill_pass`.`invoice_recieved_date` as date) AS `invoicerecieveddate`,`vowsls`.`bill_pass`.`tcs_percentage` AS `tcspercentage`,cast(`vowsls`.`bill_pass`.`invoice_date` as date) AS `invoicedate`,sum(`vowsls`.`bill_pass`.`invoice_amount`) AS `Invoiceamount`,round(sum(`vowsls`.`billpass_line_items`.`igst_amount`),0) AS `Igst`,round(sum(`vowsls`.`billpass_line_items`.`cgst_amount`),0) AS `Cgst`,round(sum(`vowsls`.`billpass_line_items`.`sgst_amount`),0) AS `Sgst`,sum(`vowsls`.`billpass_line_items`.`qty`) AS `Quantity`,sum((`vowsls`.`billpass_line_items`.`rate` * `vowsls`.`billpass_line_items`.`qty`)) AS `Amount`,`vowsls`.`costmaster`.`cost_desc` AS `costcenter`,`vowsls`.`suppliermaster`.`supp_name` AS `Vendor`,`vowsls`.`type_master`.`type_desc` AS `taxtype`,`vowsls`.`project_master`.`prj_name` AS `Branch` from (((((`vowsls`.`bill_pass` join `vowsls`.`billpass_line_items` on((`vowsls`.`bill_pass`.`bill_pass_trans_no` = `vowsls`.`billpass_line_items`.`bill_pass_hdr_id`))) join `vowsls`.`costmaster` on(((`vowsls`.`costmaster`.`id` = `vowsls`.`billpass_line_items`.`cost_center_id`) and (`vowsls`.`costmaster`.`company_id` = `vowsls`.`billpass_line_items`.`company_id`)))) join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`bill_pass`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`bill_pass`.`company_id`)))) join `vowsls`.`type_master` on((`vowsls`.`type_master`.`type_id` = `vowsls`.`bill_pass`.`tax_type`))) join `vowsls`.`project_master` on(((`vowsls`.`project_master`.`prj_id` = `vowsls`.`bill_pass`.`project_id`) and (`vowsls`.`project_master`.`company_id` = `vowsls`.`bill_pass`.`company_id`)))) where (`vowsls`.`bill_pass`.`bill_type` = 'o') group by `vowsls`.`bill_pass`.`company_id`,`ac_year`,`Billdate`,`Unit`,`vowsls`.`billpass_line_items`.`rate`,`vowsls`.`billpass_line_items`.`description`,`Invoiceno`,`paymentduedate`,`invoicerecieveddate`,`tcspercentage`,`invoicedate`,`billno`,`costcenter`,`Vendor`,`taxtype`,`Branch`;;
CREATE OR REPLACE VIEW emp_sub_dep_wise_desig_wise_summary AS select `d`.`dept_code` AS `Department Code`,`d`.`dept_desc` AS `Department Description`,`ds`.`desig` AS `Designation`,`w`.`company_id` AS `Company Id`,count(`w`.`eb_id`) AS `No of Employees` from ((`vowsls`.`worker_master` `w` join `vowsls`.`department_master` `d` on((`d`.`dept_id` = `w`.`dept_id`))) join `vowsls`.`designation` `ds` on((`ds`.`id` = `w`.`desg_id`))) group by `w`.`dept_id`,`w`.`desg_id` order by `d`.`dept_desc`,`ds`.`desig`;;
CREATE OR REPLACE VIEW gate_hdr_view AS select `p`.`company_id` AS `company_id`,`cm`.`company_code` AS `Company Code`,`p`.`branch_id` AS `Branch Id`,`bm`.`branch_name` AS `Branch Name`,`l`.`dtl_id` AS `Inward Tran No`,round((`l`.`approved_qty` * `l`.`rate`),0) AS `Value`,`p`.`project_id` AS `Project Id`,`pm`.`prj_name` AS `Project Name`,`p`.`fin_year` AS `Ac Year`,`p`.`hdr_id` AS `Entry No Id`,`p`.`in_date` AS `Entry_Date`,`su`.`supp_code` AS `Supplier Code`,`su`.`supp_name` AS `Supplier`,`l`.`po_no` AS `Po Num`,`l`.`po_line_no` AS `Po Line No`,`p`.`status` AS `Status Id`,`sm`.`status_name` AS `status_name`,`l`.`item_grp` AS `Group Code`,`igm`.`group_desc` AS `Group Name`,`l`.`item_code` AS `Item Code`,`im`.`item_desc` AS `Item Desc`,`l`.`quantity` AS `Inward Quantity`,`l`.`approved_qty` AS `Approve Quantiry`,(`l`.`quantity` - `l`.`approved_qty`) AS `Reject Quantity`,`l`.`rate` AS `Master Rate` from ((((((((`vowsls`.`gate_store_entry_reg_hdr` `p` join `vowsls`.`gate_store_entry_reg_dtl` `l` on(((`l`.`hdr_id` = `p`.`hdr_id`) and (`l`.`is_active` = 1)))) left join `vowsls`.`company_master` `cm` on((`cm`.`comp_id` = `p`.`company_id`))) left join `vowsls`.`branch_master` `bm` on((`bm`.`branch_id` = `p`.`branch_id`))) left join `vowsls`.`project_master` `pm` on((`pm`.`prj_id` = `p`.`project_id`))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `p`.`status`))) left join `vowsls`.`item_group_master` `igm` on(((`igm`.`group_code` = `l`.`item_grp`) and (`p`.`company_id` = `igm`.`company_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`item_code` = `l`.`item_code`) and (`im`.`group_code` = `l`.`item_grp`) and (`im`.`company_id` = `p`.`company_id`) and (`im`.`is_active` = 1)))) left join `vowsls`.`suppliermaster` `su` on(((`su`.`company_id` = `p`.`company_id`) and (`su`.`supp_code` = `p`.`supp_code`))));;
CREATE OR REPLACE VIEW indent_hdr_view AS select `h`.`company_id` AS `company_id`,`c`.`company_name` AS `Comapny Name`,`h`.`indent_no` AS `Indent No`,cast(`h`.`indent_date` as date) AS `Indent_Date`,round((`l`.`indent_qty` * `l`.`rate`),2) AS `Value`,`l`.`indent_srl_no` AS `Indent Tran No`,`h`.`indent_type` AS `Indent Type`,`b`.`branch_name` AS `Branch Name`,`h`.`project_id` AS `Project Id`,`pm`.`prj_name` AS `Project Name`,`h`.`remarks` AS `Remarks`,`h`.`internal_note` AS `Internal Note`,`h`.`indent_status` AS `Status Id`,`st`.`status_name` AS `Status`,`h`.`fin_year` AS `Ac Year`,`ud`.`first_name` AS `Created By`,`l`.`dept_code` AS `Dept Id`,`md`.`dept_desc` AS `Department`,`l`.`group_code` AS `Group Code`,`igm`.`group_desc` AS `Group Name`,`l`.`item_code` AS `Item Code`,`im`.`item_desc` AS `Item Name`,`l`.`indent_qty` AS `Indent Qty`,`l`.`po_placed` AS `Po Placed`,`l`.`uom_code` AS `uom_code`,`l`.`rate` AS `master_rate` from (((((((((`vowsls`.`scm_indent_hdr` `h` left join `vowsls`.`scm_indent_line_item` `l` on(((`l`.`indent_type` <> 'J') and (`h`.`indent_no` = `l`.`indent_no`) and (`h`.`company_id` = `l`.`company_id`) and (`h`.`fin_year` = `l`.`fin_year`)))) left join `vowsls`.`company_master` `c` on((`h`.`company_id` = `c`.`comp_id`))) left join `vowsls`.`branch_master` `b` on((`h`.`branch_id` = `b`.`branch_id`))) left join `vowsls`.`status_master` `st` on((`st`.`status_id` = `h`.`indent_status`))) left join `vowsls`.`master_department` `md` on(((`md`.`mdept_id` = `l`.`dept_code`) and (`md`.`company_id` = `l`.`company_id`)))) left join `vowsls`.`project_master` `pm` on((`pm`.`prj_id` = `h`.`project_id`))) left join `vowsls`.`item_group_master` `igm` on(((`igm`.`group_code` = `l`.`group_code`) and (`igm`.`company_id` = `l`.`company_id`)))) left join `vowsls`.`user_details` `ud` on((`l`.`created_by` = `ud`.`user_id`))) left join `vowsls`.`itemmaster` `im` on(((`im`.`item_code` = `l`.`item_code`) and (`im`.`company_id` = `l`.`company_id`) and (`im`.`group_code` = `l`.`group_code`) and (`im`.`is_active` = 1)))) where (`l`.`is_active` = 1);;
CREATE OR REPLACE VIEW inventory_category_graph AS select `vowsls`.`view_store_stock_inventory_category_wise`.`company_id` AS `company_id`,`vowsls`.`view_store_stock_inventory_category_wise`.`itemgroup` AS `itemgroup`,'Open' AS `value`,`vowsls`.`view_store_stock_inventory_category_wise`.`opening` AS `Open` from `vowsls`.`view_store_stock_inventory_category_wise` union select `vowsls`.`view_store_stock_inventory_category_wise`.`company_id` AS `company_id`,`vowsls`.`view_store_stock_inventory_category_wise`.`itemgroup` AS `itemgroup`,'Indent' AS `value`,`vowsls`.`view_store_stock_inventory_category_wise`.`indent` AS `Indent` from `vowsls`.`view_store_stock_inventory_category_wise` union select `vowsls`.`view_store_stock_inventory_category_wise`.`company_id` AS `company_id`,`vowsls`.`view_store_stock_inventory_category_wise`.`itemgroup` AS `itemgroup`,'Po Placed' AS `value`,`vowsls`.`view_store_stock_inventory_category_wise`.`poplaced` AS `Poplaced` from `vowsls`.`view_store_stock_inventory_category_wise` union select `vowsls`.`view_store_stock_inventory_category_wise`.`company_id` AS `company_id`,`vowsls`.`view_store_stock_inventory_category_wise`.`itemgroup` AS `itemgroup`,'Received' AS `Value`,`vowsls`.`view_store_stock_inventory_category_wise`.`receivedvalue` AS `receivedvalue` from `vowsls`.`view_store_stock_inventory_category_wise` union select `vowsls`.`view_store_stock_inventory_category_wise`.`company_id` AS `company_id`,`vowsls`.`view_store_stock_inventory_category_wise`.`itemgroup` AS `itemgroup`,'Pending' AS `value`,`vowsls`.`view_store_stock_inventory_category_wise`.`pending` AS `pending` from `vowsls`.`view_store_stock_inventory_category_wise` union select `vowsls`.`view_store_stock_inventory_category_wise`.`company_id` AS `company_id`,`vowsls`.`view_store_stock_inventory_category_wise`.`itemgroup` AS `itemgroup`,'Final' AS `value`,`vowsls`.`view_store_stock_inventory_category_wise`.`finalstock` AS `finalstock` from `vowsls`.`view_store_stock_inventory_category_wise`;;
CREATE OR REPLACE VIEW inventory_report AS select `hdr`.`ac_year` AS `Ac_year`,`hdr`.`company_id` AS `Company_id`,`Pro`.`prj_name` AS `Project`,`Branch`.`branch_name` AS `Phase`,`Indent`.`indent_type_desc` AS `Type`,`Item`.`group_desc` AS `Item_Group`,`Master`.`item_desc` AS `Item_Name`,`sr_line`.`uom_code` AS `Uom`,sum(`Master`.`op_2018`) AS `Opening Stock`,round(sum(`gate`.`quantity`),0) AS `Quantity Ordered`,round(sum(`sr_line`.`final_qty`),0) AS `Quantity Received`,round(sum(`sr_line`.`quantity_consumed`),0) AS `Issued`,round(sum(`sr_line`.`stock_transer_quantity`),0) AS `Trasfer`,sum(`retrn`.`return_qty`) AS `Return`,sum(`Issue`.`issue_qty`) AS `Consumed` from ((((((((((`vowsls`.`scm_sr_hdr` `hdr` join `vowsls`.`branch_master` `Branch` on((`hdr`.`branch_id` = `Branch`.`branch_id`))) join `vowsls`.`project_master` `Pro` on((`Pro`.`prj_id` = `hdr`.`project_id`))) join `vowsls`.`scm_indent_type_master` `Indent` on((`Indent`.`indent_type_code` = `hdr`.`expense_type`))) join `vowsls`.`scm_sr_line_item` `sr_line` on((`hdr`.`store_receive_no` = `sr_line`.`store_receive_no`))) left join `vowsls`.`item_group_master` `Item` on(((`Item`.`group_code` = `sr_line`.`item_grp_id`) and (`hdr`.`company_id` = `Item`.`company_id`)))) join `vowsls`.`itemmaster` `Master` on(((`sr_line`.`item_code` = `Master`.`item_code`) and (`Master`.`company_id` = `hdr`.`company_id`) and (`Master`.`group_code` = `Item`.`group_code`)))) join `vowsls`.`scm_issue_hdr` `Issue` on(((`sr_line`.`item_code` = `Issue`.`item_code`) and (`Issue`.`branch_id` = `hdr`.`branch_id`) and (`Issue`.`company_id` = `hdr`.`company_id`) and (`Issue`.`project_id` = `hdr`.`project_id`)))) join `vowsls`.`gate_store_entry_reg_dtl` `gate` on((`sr_line`.`item_code` = `gate`.`item_code`))) left join `vowsls`.`gate_store_entry_reg_hdr` `entry` on(((`entry`.`hdr_id` = `gate`.`dtl_id`) and (`entry`.`company_id` = `hdr`.`company_id`) and (`entry`.`project_id` = `hdr`.`project_id`)))) join `vowsls`.`scm_return_hdr` `retrn` on(((`sr_line`.`item_code` = `retrn`.`item_code`) and (`retrn`.`branch_id` = `hdr`.`branch_id`) and (`retrn`.`project_id` = `hdr`.`project_id`) and (`retrn`.`company_id` = `hdr`.`company_id`)))) group by `hdr`.`ac_year`,`hdr`.`company_id`,`Project`,`Phase`,`Type`,`Item_Group`,`Item_Name`,`sr_line`.`uom_code`;;
CREATE OR REPLACE VIEW inventory_stock AS select `hdr`.`ac_year` AS `year`,`hdr`.`company_id` AS `company`,`Pro`.`prj_name` AS `project`,`Branch`.`branch_name` AS `PHASE`,`Indent`.`indent_type_desc` AS `type`,`Item`.`group_desc` AS `itemgroup`,`Master`.`item_desc` AS `itemname`,`sr_line`.`uom_code` AS `uom`,sum(`Master`.`op_2018`) AS `openingstock`,round(sum(`gate`.`quantity`),0) AS `quantityorderd`,round(sum(`sr_line`.`final_qty`),0) AS `quantityreceived`,round(sum(`sr_line`.`quantity_consumed`),0) AS `issued`,round(sum(`sr_line`.`stock_transer_quantity`),0) AS `trasfer`,sum(`retrn`.`return_qty`) AS `retun`,sum(`Issue`.`issue_qty`) AS `Consumed` from ((((((((((`vowsls`.`scm_sr_hdr` `hdr` join `vowsls`.`branch_master` `Branch` on((`hdr`.`branch_id` = `Branch`.`branch_id`))) join `vowsls`.`project_master` `Pro` on((`Pro`.`prj_id` = `hdr`.`project_id`))) join `vowsls`.`scm_indent_type_master` `Indent` on((`Indent`.`indent_type_code` = `hdr`.`expense_type`))) join `vowsls`.`scm_sr_line_item` `sr_line` on((`hdr`.`store_receive_no` = `sr_line`.`store_receive_no`))) left join `vowsls`.`item_group_master` `Item` on(((`Item`.`group_code` = `sr_line`.`item_grp_id`) and (`hdr`.`company_id` = `Item`.`company_id`)))) join `vowsls`.`itemmaster` `Master` on(((`sr_line`.`item_code` = `Master`.`item_code`) and (`Master`.`company_id` = `hdr`.`company_id`) and (`Master`.`group_code` = `Item`.`group_code`)))) join `vowsls`.`scm_issue_hdr` `Issue` on(((`sr_line`.`item_code` = `Issue`.`item_code`) and (`Issue`.`branch_id` = `hdr`.`branch_id`) and (`Issue`.`company_id` = `hdr`.`company_id`) and (`Issue`.`project_id` = `hdr`.`project_id`)))) join `vowsls`.`gate_store_entry_reg_dtl` `gate` on((`sr_line`.`item_code` = `gate`.`item_code`))) left join `vowsls`.`gate_store_entry_reg_hdr` `entry` on(((`entry`.`hdr_id` = `gate`.`dtl_id`) and (`entry`.`company_id` = `hdr`.`company_id`) and (`entry`.`project_id` = `hdr`.`project_id`)))) join `vowsls`.`scm_return_hdr` `retrn` on(((`sr_line`.`item_code` = `retrn`.`item_code`) and (`retrn`.`branch_id` = `hdr`.`branch_id`) and (`retrn`.`project_id` = `hdr`.`project_id`) and (`retrn`.`company_id` = `hdr`.`company_id`)))) group by `year`,`company`,`project`,`PHASE`,`type`,`itemgroup`,`itemname`,`sr_line`.`uom_code`;;
CREATE OR REPLACE VIEW issue_hdr_view AS select `l`.`issue_no` AS `issue_no`,`l`.`hdr_id` AS `hdr_id`,`l`.`sr_line_id` AS `sr_line_id`,`l`.`sr_no` AS `sr_no`,`l`.`company_id` AS `company_id`,`l`.`fin_year` AS `fin_year`,`bm`.`branch_name` AS `branch_name`,`pm`.`prj_name` AS `prj_name`,`l`.`issue_date` AS `issue_date`,`cm`.`name` AS `name`,`sm`.`status_name` AS `status_name`,`l`.`dept_id` AS `dept_id`,`md`.`dept_desc` AS `dept_desc`,`mm`.`mechine_name` AS `mechine_name`,`l`.`group_code` AS `group_code`,`igm`.`group_desc` AS `group_desc`,`l`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_desc`,`l`.`uom_code` AS `uom_code`,`l`.`issue_qty` AS `issue_qty`,`l`.`issue_value` AS `issue_value`,round((`l`.`issue_value` / `l`.`issue_qty`),2) AS `rate`,`l`.`created_by` AS `created_by`,`l`.`create_date` AS `create_date`,`l`.`mod_on` AS `mod_on`,`l`.`mod_by` AS `mod_by` from ((((((((`vowsls`.`scm_issue_hdr` `l` left join `vowsls`.`master_department` `md` on(((`md`.`mdept_id` = `l`.`dept_id`) and (`md`.`company_id` = `l`.`company_id`)))) left join `vowsls`.`item_group_master` `igm` on(((`igm`.`group_code` = `l`.`group_code`) and (`igm`.`company_id` = `l`.`company_id`)))) left join `vowsls`.`branch_master` `bm` on((`bm`.`branch_id` = `l`.`branch_id`))) left join `vowsls`.`project_master` `pm` on((`pm`.`prj_id` = `l`.`project_id`))) left join `vowsls`.`mechine_master` `mm` on((`mm`.`mechine_id` = `l`.`machine_id`))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `l`.`issue_status`))) left join `vowsls`.`customer_master` `cm` on((`cm`.`id` = `l`.`customer_id`))) left join `vowsls`.`itemmaster` `im` on(((`im`.`item_code` = `l`.`item_code`) and (`im`.`company_id` = `l`.`company_id`) and (`im`.`group_code` = `l`.`group_code`)))) where (`l`.`is_active` = 1);;
CREATE OR REPLACE VIEW item_code_wise_indent_po AS select `vowsls`.`scm_indent_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_indent_hdr`.`fin_year` AS `ac_year`,`vowsls`.`scm_indent_line_item`.`item_code` AS `itemcode`,`vowsls`.`scm_indent_line_item`.`group_code` AS `group_code`,concat(`vowsls`.`scm_indent_line_item`.`group_code`,`vowsls`.`scm_indent_line_item`.`item_code`) AS `item_unique_no`,`vowsls`.`itemmaster`.`item_desc` AS `Itemdescription`,`vowsls`.`scm_indent_hdr`.`indent_no` AS `indentno`,cast(`vowsls`.`scm_indent_hdr`.`indent_date` as date) AS `indentdate`,`vowsls`.`scm_po_hdr`.`po_num` AS `ponum`,`vowsls`.`scm_po_hdr`.`po_date` AS `podate` from ((((`vowsls`.`scm_indent_hdr` join `vowsls`.`scm_indent_line_item` on(((`vowsls`.`scm_indent_hdr`.`indent_no` = `vowsls`.`scm_indent_line_item`.`indent_no`) and (`vowsls`.`scm_indent_hdr`.`company_id` = `vowsls`.`scm_indent_line_item`.`company_id`) and (`vowsls`.`scm_indent_hdr`.`is_active` = 1) and (`vowsls`.`scm_indent_line_item`.`is_active` = 1)))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_indent_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_indent_hdr`.`company_id`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_indent_line_item`.`group_code`)))) left join `vowsls`.`scm_po_line_item` on(((`vowsls`.`scm_po_line_item`.`indent_no` = `vowsls`.`scm_indent_line_item`.`indent_srl_no`) and (`vowsls`.`scm_po_line_item`.`is_active` = 1)))) left join `vowsls`.`scm_po_hdr` on((`vowsls`.`scm_po_hdr`.`po_num` = `vowsls`.`scm_po_line_item`.`po_num`))) where (`vowsls`.`scm_indent_hdr`.`indent_type` <> 'J');;
CREATE OR REPLACE VIEW item_wise_consumption_view AS select `i`.`item_code` AS `item_code`,`i`.`item_desc` AS `item_desc`,round(sum(`l`.`quantity_consumed`),3) AS `consumed_quantity`,round((sum(`l`.`final_qty`) - sum(`l`.`quantity_consumed`)),3) AS `available_quantity`,round(sum((`l`.`quantity_consumed` * `l`.`rate`)),2) AS `consumed_value`,round(sum(((`l`.`final_qty` - `l`.`quantity_consumed`) * `l`.`rate`)),2) AS `available_value`,`h`.`ac_year` AS `fin_year`,`h`.`company_id` AS `company_id` from (((`vowsls`.`scm_sr_hdr` `h` join `vowsls`.`scm_sr_line_item` `l`) join `vowsls`.`itemmaster` `i`) join `vowsls`.`scm_issue_hdr` `si`) where ((`h`.`store_receive_no` = `l`.`store_receive_no`) and (`l`.`item_code` = `i`.`item_code`) and (`i`.`group_code` = `l`.`item_grp_id`) and ((`l`.`final_qty` - `l`.`quantity_consumed`) > 0) and (`si`.`sr_line_id` = `l`.`store_line_item_no`)) group by `i`.`item_code`,`i`.`item_desc`,`h`.`ac_year`,`h`.`company_id`;;
CREATE OR REPLACE VIEW item_wise_jute_stock_widget AS select `vowsls`.`jute_issue`.`company_id` AS `company_id`,`vowsls`.`jute_issue`.`fin_year` AS `ac_year`,sum(`vowsls`.`jute_issue`.`jute_quality`) AS `quantity`,`vowsls`.`itemmaster`.`item_desc` AS `itemname` from (`vowsls`.`jute_issue` join `vowsls`.`itemmaster` on((`vowsls`.`jute_issue`.`jute_type` = `vowsls`.`itemmaster`.`item_code`))) group by `vowsls`.`jute_issue`.`company_id`,`ac_year`,`itemname`;;
CREATE OR REPLACE VIEW itemgroupwise_dashboard1 AS select `indenthead0_`.`company_id` AS `company_id`,`indenthead0_`.`branch_id` AS `branch_id`,`indenthead0_`.`project_id` AS `project_id`,`indenthead0_`.`indent_status` AS `indent_status`,`poheader3_`.`po_status` AS `po_status`,`indent1_`.`indent_type` AS `indent_type`,`indenthead0_`.`indent_date` AS `indent_date`,round(sum((`storegoodr5_`.`final_qty` * `storegoodr5_`.`rate`)),0) AS `srfinalvalue`,round(sum((`storegoodr5_`.`quantity_consumed` * `storegoodr5_`.`rate`)),0) AS `srconsumedvalue`,round(sum((`storegoodr5_`.`stock_transer_quantity` * `storegoodr5_`.`rate`)),0) AS `srtransfervalue`,round(sum((`polineitem2_`.`quantity` * `polineitem2_`.`rate`)),0) AS `povalue`,round(sum(`polineitem2_`.`gate_po_placed`),0) AS `poplaced`,round(sum((`indent1_`.`indent_qty` * `indent1_`.`rate`)),0) AS `indentvalue`,round(sum((`indent1_`.`po_placed` * `indent1_`.`rate`)),0) AS `indentplaced`,round(sum(((`indent1_`.`indent_qty` * `indent1_`.`rate`) - (`indent1_`.`po_placed` * `indent1_`.`rate`))),0) AS `remainingindentvalue`,`indent1_`.`group_code` AS `group_code` from (((((`vowsls`.`scm_indent_hdr` `indenthead0_` join `vowsls`.`scm_indent_line_item` `indent1_`) join `vowsls`.`scm_po_line_item` `polineitem2_`) join `vowsls`.`scm_po_hdr` `poheader3_`) join `vowsls`.`gate_store_entry_reg_dtl` `gatestoree4_`) join `vowsls`.`scm_sr_line_item` `storegoodr5_`) where ((`indent1_`.`indent_no` = `indenthead0_`.`indent_no`) and (`indenthead0_`.`company_id` = `indent1_`.`company_id`) and (`indenthead0_`.`fin_year` = `indent1_`.`fin_year`) and (`indent1_`.`is_active` = 1) and (`gatestoree4_`.`is_active` = 1) and (`storegoodr5_`.`gate_line_item_no` = `gatestoree4_`.`dtl_id`) and (`gatestoree4_`.`po_line_no` = `polineitem2_`.`line_item_num`) and (`indent1_`.`indent_type` <> 'J') and (`polineitem2_`.`indent_no` = `indent1_`.`indent_srl_no`) and (`polineitem2_`.`po_num` = `poheader3_`.`po_num`) and (`polineitem2_`.`is_active` = 1)) group by `indenthead0_`.`company_id`,`indent1_`.`group_code`,`indenthead0_`.`indent_status`,`poheader3_`.`po_status`,`indent1_`.`indent_type`,`indenthead0_`.`branch_id`,`indenthead0_`.`project_id`,`indenthead0_`.`indent_date`;;
CREATE OR REPLACE VIEW jute_current_stock AS select `vowsls`.`scm_mr_line_item`.`company_id` AS `company_id`,ifnull(round(sum((`vowsls`.`scm_mr_line_item`.`actual_bale` - `vowsls`.`scm_mr_line_item`.`bales_consumed`)),0),0) AS `bales`,ifnull(round(sum((`vowsls`.`scm_mr_line_item`.`actual_loose` - `vowsls`.`scm_mr_line_item`.`drums_consumed`)),0),0) AS `bundles`,ifnull(sum(`vowsls`.`scm_mr_line_item`.`actual_quality`),0) AS `quality`,round(sum(((`vowsls`.`scm_mr_line_item`.`accepted_weight` / 100) - `vowsls`.`scm_mr_line_item`.`weight_consumed`)),0) AS `qty`,round(sum(((`vowsls`.`scm_mr_line_item`.`rate` * (`vowsls`.`scm_mr_line_item`.`accepted_weight` / 100)) - `vowsls`.`scm_mr_line_item`.`weight_consumed`)),0) AS `value`,`vowsls`.`itemmaster`.`item_desc` AS `juteitem`,`vowsls`.`warehouse_details`.`name` AS `godown` from ((`vowsls`.`scm_mr_line_item` join `vowsls`.`itemmaster` on(((`vowsls`.`scm_mr_line_item`.`item_code` = `vowsls`.`itemmaster`.`item_code`) and (`vowsls`.`scm_mr_line_item`.`company_id` = `vowsls`.`itemmaster`.`company_id`)))) join `vowsls`.`warehouse_details` on(((`vowsls`.`warehouse_details`.`id` = `vowsls`.`scm_mr_line_item`.`warehouse_no`) and (`vowsls`.`warehouse_details`.`company_id` = `vowsls`.`scm_mr_line_item`.`company_id`)))) where (`vowsls`.`itemmaster`.`group_code` = '999') group by `vowsls`.`scm_mr_line_item`.`company_id`,`juteitem`,`godown`;;
CREATE OR REPLACE VIEW jute_line_widget AS select `vowsls`.`jute_issue`.`company_id` AS `company_id`,extract(year_month from `vowsls`.`jute_issue`.`issue_date`) AS `monyear`,monthname(`vowsls`.`jute_issue`.`issue_date`) AS `monthna`,round((sum(`vowsls`.`jute_issue`.`quantity`) / 10),0) AS `quantity`,'jute issue' AS `juteissue` from `vowsls`.`jute_issue` group by `vowsls`.`jute_issue`.`company_id`,`monyear`,`monthna`,`juteissue` order by `monyear`;;
CREATE OR REPLACE VIEW last_month_jute_consumption AS select `vowsls`.`jute_issue`.`company_id` AS `company_id`,`vowsls`.`jute_issue`.`fin_year` AS `ac_year`,round(sum(`vowsls`.`jute_issue`.`issue_value`),0) AS `Value`,`vowsls`.`itemmaster`.`item_desc` AS `itemname`,'itemconsumption' AS `itemconsumption` from (`vowsls`.`jute_issue` join `vowsls`.`itemmaster` on(((`vowsls`.`jute_issue`.`jute_type` = `vowsls`.`itemmaster`.`item_code`) and (`vowsls`.`jute_issue`.`company_id` = `vowsls`.`itemmaster`.`company_id`)))) where ((year(`vowsls`.`jute_issue`.`issue_date`) = year((curdate() - interval 1 month))) and (month(`vowsls`.`jute_issue`.`issue_date`) = month((curdate() - interval 1 month)))) group by `vowsls`.`jute_issue`.`company_id`,`itemname`,`ac_year`,`itemconsumption` order by `itemname` desc limit 10;;
CREATE OR REPLACE VIEW latest_jute_consumption AS select `vowsls`.`jute_issue`.`company_id` AS `company_id`,`vowsls`.`jute_issue`.`fin_year` AS `ac_year`,round(sum(`vowsls`.`jute_issue`.`issue_value`),0) AS `Value`,`vowsls`.`itemmaster`.`item_desc` AS `itemname`,`vowsls`.`jute_issue`.`issue_date` AS `date` from (`vowsls`.`jute_issue` join `vowsls`.`itemmaster` on(((`vowsls`.`jute_issue`.`jute_type` = `vowsls`.`itemmaster`.`item_code`) and (`vowsls`.`jute_issue`.`company_id` = `vowsls`.`itemmaster`.`company_id`)))) where ((`vowsls`.`itemmaster`.`group_code` = '999') and (year(`vowsls`.`jute_issue`.`issue_date`) = year((curdate() - interval 1 month))) and (month(`vowsls`.`jute_issue`.`issue_date`) = month((curdate() - interval 1 month)))) group by `vowsls`.`jute_issue`.`company_id`,`itemname`,`ac_year`,`date`;;
CREATE OR REPLACE VIEW month_wise_purchase AS select `vowsls`.`scm_po_hdr`.`fin_year` AS `ac_year`,extract(year_month from `vowsls`.`scm_po_hdr`.`po_date`) AS `pomonth`,monthname(`vowsls`.`scm_po_hdr`.`po_date`) AS `month`,round(sum(`vowsls`.`scm_po_hdr`.`po_val_wt_tax`),0) AS `amount`,`vowsls`.`scm_po_hdr`.`company_id` AS `company_id`,'purchase' AS `salepurchase` from `vowsls`.`scm_po_hdr` group by `pomonth`,`month`,`vowsls`.`scm_po_hdr`.`company_id`,`ac_year` order by `pomonth` limit 24;;
CREATE OR REPLACE VIEW month_wise_salepurchase AS select `vowsls`.`month_wise_sales_widget`.`month` AS `month`,`vowsls`.`month_wise_sales_widget`.`salepurchase` AS `salepurchase`,`vowsls`.`month_wise_sales_widget`.`amount` AS `amount`,`vowsls`.`month_wise_sales_widget`.`ac_year` AS `ac_year`,`vowsls`.`month_wise_sales_widget`.`company_id` AS `company_id` from `vowsls`.`month_wise_sales_widget` union select `vowsls`.`month_wise_purchase`.`month` AS `month`,`vowsls`.`month_wise_purchase`.`salepurchase` AS `salepurchase`,`vowsls`.`month_wise_purchase`.`amount` AS `amount`,`vowsls`.`month_wise_purchase`.`ac_year` AS `ac_year`,`vowsls`.`month_wise_purchase`.`company_id` AS `company_id` from `vowsls`.`month_wise_purchase`;;
CREATE OR REPLACE VIEW month_wise_sales_widget AS select extract(year_month from `vowsls`.`invoice_hdr`.`invoice_date`) AS `monyear`,monthname(`vowsls`.`invoice_hdr`.`invoice_date`) AS `month`,round(sum(`vowsls`.`invoice_hdr`.`invoice_amount`),0) AS `amount`,`vowsls`.`invoice_hdr`.`company_id` AS `company_id`,`vowsls`.`invoice_hdr`.`ac_year` AS `ac_year`,'sales' AS `salepurchase` from `vowsls`.`invoice_hdr` group by `monyear`,`month`,`vowsls`.`invoice_hdr`.`company_id`,`vowsls`.`invoice_hdr`.`ac_year` order by `monyear`;;
CREATE OR REPLACE VIEW mukham_moisture_analysis AS select `smh`.`supp_code` AS `supp_code`,`s`.`supp_name` AS `supp_name`,`m`.`mukam_name` AS `mukam_name`,`smh`.`mr_print_no` AS `mr_print_no`,cast(`smh`.`jute_receive_dt` as date) AS `jute_receive_dt`,`smh`.`company_id` AS `company_id`,`smh`.`mukam_id` AS `mukam_id`,`smli`.`claims_condition` AS `claims_condition`,`mm`.`moisture` AS `moisture`,round((((`smli`.`claims_condition` * 100) / `mm`.`moisture`) - 100),2) AS `deviation` from ((((`vowsls`.`scm_mr_hdr` `smh` join `vowsls`.`scm_mr_line_item` `smli` on((`smh`.`jute_receive_no` = `smli`.`jute_receive_no`))) join `vowsls`.`suppliermaster` `s` on(((`s`.`company_id` = `smh`.`company_id`) and (`s`.`supp_code` = `smh`.`supp_code`)))) join `vowsls`.`mukam` `m` on(((`m`.`company_id` = `smh`.`company_id`) and (`m`.`mukam_id` = `smh`.`mukam_id`)))) join (select `smh`.`mukam_id` AS `mukam_id`,round(avg(`smli`.`claims_condition`),2) AS `moisture` from (`vowsls`.`scm_mr_hdr` `smh` join `vowsls`.`scm_mr_line_item` `smli` on((`smh`.`jute_receive_no` = `smli`.`jute_receive_no`))) where (`smh`.`mukam_id` is not null) group by `smh`.`mukam_id`) `mm` on((`smh`.`mukam_id` = `mm`.`mukam_id`))) where ((`smh`.`mukam_id` is not null) and (`smli`.`claims_condition` > `mm`.`moisture`));;
CREATE OR REPLACE VIEW on_roll_worker_category_wise_view AS select `cm`.`cata_desc` AS `category_description`,count(`wm`.`eb_id`) AS `EmployeeCount`,`cm`.`company_id` AS `company_id`,'Category' AS `departmentcategory` from (`vowsls`.`worker_master` `wm` join `vowsls`.`category_master` `cm`) where ((`cm`.`cata_id` = `wm`.`cata_id`) and (`wm`.`active` = 'Y')) group by `category_description`,`cm`.`company_id`;;
CREATE OR REPLACE VIEW on_roll_worker_department_wise_view AS select `dm`.`dept_desc` AS `department_description`,count(`wm`.`eb_id`) AS `EmployeeCount`,`dm`.`company_id` AS `company_id`,'Department' AS `departmentcategory` from (`vowsls`.`worker_master` `wm` join `vowsls`.`department_master` `dm`) where ((`dm`.`dept_id` = `wm`.`dept_id`) and (`wm`.`active` = 'Y')) group by `department_description`,`dm`.`company_id`;;
CREATE OR REPLACE VIEW on_roll_worker_summary_widget AS select `vowsls`.`on_roll_worker_category_wise_view`.`category_description` AS `category_description`,`vowsls`.`on_roll_worker_category_wise_view`.`departmentcategory` AS `departmentcategory`,`vowsls`.`on_roll_worker_category_wise_view`.`EmployeeCount` AS `EmployeeCount`,`vowsls`.`on_roll_worker_category_wise_view`.`company_id` AS `company_id` from `vowsls`.`on_roll_worker_category_wise_view` union select `vowsls`.`on_roll_worker_department_wise_view`.`department_description` AS `department_description`,`vowsls`.`on_roll_worker_department_wise_view`.`departmentcategory` AS `departmentcategory`,`vowsls`.`on_roll_worker_department_wise_view`.`EmployeeCount` AS `EmployeeCount`,`vowsls`.`on_roll_worker_department_wise_view`.`company_id` AS `company_id` from `vowsls`.`on_roll_worker_department_wise_view`;;
CREATE OR REPLACE VIEW payments_due AS select `h`.`ac_year` AS `ac_year`,`b`.`branch_id` AS `branch_id`,`b`.`branch_name` AS `Branch`,`h`.`company_id` AS `company_id`,round(sum(`l`.`amount_with_tax`),0) AS `Supplied`,(select round(sum(`vowsls`.`bill_pass`.`net_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`company_id` = `h`.`company_id`) and (`vowsls`.`bill_pass`.`branch_id` = `b`.`branch_id`) and (`vowsls`.`bill_pass`.`bill_type` = 'S') and (`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`))) AS `Billpassed`,((select round(sum(`vowsls`.`bill_pass`.`net_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`company_id` = `h`.`company_id`) and (`vowsls`.`bill_pass`.`branch_id` = `b`.`branch_id`) and (`vowsls`.`bill_pass`.`bill_type` = 'S') and (`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`))) - (select round(sum(`vowsls`.`bill_pass`.`due_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`company_id` = `h`.`company_id`) and (`vowsls`.`bill_pass`.`branch_id` = `b`.`branch_id`) and (`vowsls`.`bill_pass`.`bill_type` = 'S') and (`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`)))) AS `PaidAmount`,(select round(sum(`vowsls`.`bill_pass`.`due_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`company_id` = `h`.`company_id`) and (`vowsls`.`bill_pass`.`branch_id` = `b`.`branch_id`) and (`vowsls`.`bill_pass`.`bill_type` = 'S') and (`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`))) AS `Due` from ((`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h`) join `vowsls`.`branch_master` `b`) where ((`b`.`branch_id` = `h`.`branch_id`) and (`l`.`store_receive_no` = `h`.`store_receive_no`) and (`l`.`is_active` = 1)) group by `b`.`branch_name`,`h`.`company_id`,`b`.`branch_id`,`h`.`ac_year` union select `h`.`ac_year` AS `ac_year`,'Total' AS `Total`,'Total' AS `Total`,`h`.`company_id` AS `company_id`,round(sum(`l`.`amount_with_tax`),0) AS `Supplied`,(select round(sum(`vowsls`.`bill_pass`.`net_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`company_id` = `h`.`company_id`) and (`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`) and (`vowsls`.`bill_pass`.`bill_type` = 'S'))) AS `billpassed`,((select round(sum(`vowsls`.`bill_pass`.`net_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`company_id` = `h`.`company_id`) and (`vowsls`.`bill_pass`.`bill_type` = 'S') and (`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`))) - (select round(sum(`vowsls`.`bill_pass`.`due_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`company_id` = `h`.`company_id`) and (`vowsls`.`bill_pass`.`bill_type` = 'S') and (`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`)))) AS `PaidAmount`,(select round(sum(`vowsls`.`bill_pass`.`due_amount`),0) from `vowsls`.`bill_pass` where ((`vowsls`.`bill_pass`.`company_id` = `h`.`company_id`) and (`vowsls`.`bill_pass`.`fin_year` = `h`.`ac_year`) and (`vowsls`.`bill_pass`.`bill_type` = 'S'))) AS `Due` from (`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h`) where ((`l`.`store_receive_no` = `h`.`store_receive_no`) and (`l`.`is_active` = 1)) group by `h`.`company_id`,`h`.`ac_year` order by `Due` desc;;
CREATE OR REPLACE VIEW pending_po_widget AS select cast(`p`.`indent_date` as date) AS `Indent Date`,`p`.`indent_no` AS `Indent No`,`i`.`item_desc` AS `Item Name`,sum(round((`l`.`indent_qty` - `l`.`po_placed`),3)) AS `Quantity`,`l`.`item_code` AS `item_code`,(to_days(curdate()) - to_days(`p`.`indent_date`)) AS `Due Days`,`p`.`company_id` AS `company_id`,`p`.`fin_year` AS `ac_year` from (((`vowsls`.`scm_indent_hdr` `p` join `vowsls`.`scm_indent_line_item` `l`) join `vowsls`.`itemmaster` `i`) join `vowsls`.`company_master` `cm`) where ((`p`.`indent_no` = `l`.`indent_no`) and (cast(curdate() as date) > `p`.`indent_date`) and (`p`.`indent_type` <> 'J') and (`l`.`item_code` = `i`.`item_code`) and (`l`.`is_active` = 1) and (`l`.`group_code` = `i`.`group_code`) and (`p`.`company_id` = `i`.`company_id`) and (`p`.`indent_status` = 3) and (`p`.`company_id` = `l`.`company_id`) and (`p`.`indent_no` = `l`.`indent_no`) and (`p`.`fin_year` = `l`.`fin_year`) and (round((`l`.`indent_qty` - `l`.`po_placed`),3) > 0)) group by `p`.`indent_date`,`p`.`indent_no`,`p`.`company_id`,`p`.`fin_year`,`i`.`item_desc`,`l`.`item_code` order by `Due Days` desc;;
CREATE OR REPLACE VIEW po_hdr_view AS select `p`.`company_id` AS `company_id`,`u`.`first_name` AS `Created By`,`l`.`line_item_num` AS `lineitemno`,`cm`.`company_code` AS `Company Code`,`l`.`indent_no` AS `Indent Tran No`,`sili`.`indent_no` AS `Indent No`,round((`l`.`quantity` * `l`.`rate`),0) AS `Value`,`p`.`branch_id` AS `Branch Id`,`bm`.`branch_name` AS `Branch Name`,`p`.`project_id` AS `Project Id`,`pm`.`prj_name` AS `Project Name`,`p`.`fin_year` AS `Ac Year`,`p`.`po_num` AS `Po No`,cast(`p`.`po_date` as date) AS `PO_Date`,`p`.`expected_date` AS `expected_date`,`su`.`supp_name` AS `Supplier Name`,`su`.`supp_code` AS `Supplier Code`,`p`.`po_status` AS `Status Id`,`sm`.`status_name` AS `status_name`,`l`.`group_code` AS `Group Code`,`igm`.`group_desc` AS `Group Name`,`l`.`item_code` AS `Item Code`,`im`.`item_desc` AS `Item Desc`,`l`.`quantity` AS `Po Quantity`,`l`.`gate_po_placed` AS `Inward Quantity`,(`l`.`quantity` - `l`.`gate_po_placed`) AS `Due Value`,(to_days(curdate()) - to_days(`p`.`expected_date`)) AS `Exceeded Days`,`l`.`c_tax` AS `C Tax`,`l`.`s_tax` AS `S tax`,`l`.`i_tax` AS `I Tax`,`l`.`rate` AS `Master Rate`,`l`.`last_purchase_rate` AS `Last Po Rate` from ((((((((((`vowsls`.`scm_po_hdr` `p` join `vowsls`.`scm_po_line_item` `l` on(((`l`.`po_num` = `p`.`po_num`) and (`l`.`is_active` = 1)))) left join `vowsls`.`company_master` `cm` on((`cm`.`comp_id` = `p`.`company_id`))) left join `vowsls`.`branch_master` `bm` on((`bm`.`branch_id` = `p`.`branch_id`))) left join `vowsls`.`project_master` `pm` on((`pm`.`prj_id` = `p`.`project_id`))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `p`.`po_status`))) left join `vowsls`.`item_group_master` `igm` on(((`igm`.`group_code` = `l`.`group_code`) and (`p`.`company_id` = `igm`.`company_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`item_code` = `l`.`item_code`) and (`im`.`group_code` = `l`.`group_code`) and (`im`.`is_active` = 1) and (`im`.`company_id` = `p`.`company_id`)))) left join `vowsls`.`scm_indent_line_item` `sili` on((`sili`.`indent_srl_no` = `l`.`indent_no`))) left join `vowsls`.`suppliermaster` `su` on(((`su`.`supp_code` = `p`.`supp_code`) and (`su`.`company_id` = `p`.`company_id`)))) left join `vowsls`.`user_details` `u` on((`u`.`user_id` = `p`.`created_by`))) where (`p`.`po_type` <> 'J');;
CREATE OR REPLACE VIEW production_line_graph AS select `vowsls`.`cuts_jugar_buff_1`.`company_id` AS `company_id`,extract(year_month from `vowsls`.`cuts_jugar_buff_1`.`loom_date`) AS `monthna`,monthname(`vowsls`.`cuts_jugar_buff_1`.`loom_date`) AS `mon`,(sum(`vowsls`.`cuts_jugar_buff_1`.`total_production`) / 10) AS `productionqty`,'production' AS `prodction` from `vowsls`.`cuts_jugar_buff_1` group by `vowsls`.`cuts_jugar_buff_1`.`company_id`,`monthna`,`mon`,`prodction` order by `monthna`;;
CREATE OR REPLACE VIEW production_report AS select `vowsls`.`cuts_jugar_buff_1`.`company_id` AS `company_id`,`vowsls`.`cuts_jugar_buff_1`.`loom_date` AS `Date`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`production_a1`) else '0' end) AS `ProductionA1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`production_a2`) else '0' end) AS `ProductionA2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`production_b1`) else '0' end) AS `ProductionB1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`production_b2`) else '0' end) AS `ProductionB2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_c`) then sum(`vowsls`.`cuts_jugar_buff_1`.`production_c`) else '0' end) AS `ProductionC`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`close_a1`) else '0' end) AS `closeA1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`close_a2`) else '0' end) AS `closeA2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`close_b1`) else '0' end) AS `closeB1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`close_b2`) else '0' end) AS `closeB2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_c`) then sum(`vowsls`.`cuts_jugar_buff_1`.`close_c`) else '0' end) AS `closeC`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`open_a1`) else '0' end) AS `openA1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`open_a2`) else '0' end) AS `openA2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`open_b1`) else '0' end) AS `openB1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`open_b2`) else '0' end) AS `openB2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_c`) then sum(`vowsls`.`cuts_jugar_buff_1`.`open_c`) else '0' end) AS `openC`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`cuts_a1`) else '0' end) AS `cutsA1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`cuts_a2`) else '0' end) AS `cutsA2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`cuts_b1`) else '0' end) AS `cutsB1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`cuts_b2`) else '0' end) AS `cutsB2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_c`) then sum(`vowsls`.`cuts_jugar_buff_1`.`cuts_c`) else '0' end) AS `cutsC`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`jugar_a1`) else '0' end) AS `jugarA1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`jugar_a2`) else '0' end) AS `jugarA2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`jugar_b1`) else '0' end) AS `jugarB1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`jugar_b2`) else '0' end) AS `jugarB2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_c`) then sum(`vowsls`.`cuts_jugar_buff_1`.`jugar_c`) else '0' end) AS `jugarC`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`quality_code_a1`) else '0' end) AS `QuanlityA1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`quality_code_a2`) else '0' end) AS `QualityA2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`quality_code_b1`) else '0' end) AS `QualityB1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`quality_code_b2`) else '0' end) AS `QualityB2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_c`) then sum(`vowsls`.`cuts_jugar_buff_1`.`quality_code_c`) else '0' end) AS `QualityC`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`ticket_no_a1`) else '0' end) AS `ticketA1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_a2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`ticket_no_a2`) else '0' end) AS `ticketA2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b1`) then sum(`vowsls`.`cuts_jugar_buff_1`.`ticket_no_b1`) else '0' end) AS `ticketB1`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_b2`) then sum(`vowsls`.`cuts_jugar_buff_1`.`ticket_no_b2`) else '0' end) AS `ticketB2`,(case when sum(`vowsls`.`cuts_jugar_buff_1`.`efficiency_c`) then sum(`vowsls`.`cuts_jugar_buff_1`.`ticket_no_c`) else '0' end) AS `ticketC` from `vowsls`.`cuts_jugar_buff_1` group by `vowsls`.`cuts_jugar_buff_1`.`company_id`,`Date`;;
CREATE OR REPLACE VIEW quality_stock AS select `vowsls`.`jute_quality_price_master`.`jute_quality` AS `jute_quality`,`vowsls`.`scm_mr_hdr`.`ac_year` AS `ac_year`,round(((`vowsls`.`scm_mr_line_item`.`accepted_weight` / 100) - `vowsls`.`scm_mr_line_item`.`weight_consumed`),0) AS `stock` from ((`vowsls`.`jute_quality_price_master` join `vowsls`.`scm_mr_line_item` on((`vowsls`.`jute_quality_price_master`.`item_code` = `vowsls`.`scm_mr_line_item`.`item_code`))) join `vowsls`.`scm_mr_hdr` on((`vowsls`.`scm_mr_hdr`.`jute_receive_no` = `vowsls`.`scm_mr_line_item`.`jute_receive_no`))) where (round(((`vowsls`.`scm_mr_line_item`.`accepted_weight` / 100) - `vowsls`.`scm_mr_line_item`.`weight_consumed`),0) > 0);;
CREATE OR REPLACE VIEW quality_wise_stock AS select `vowsls`.`jute_quality_price_master`.`jute_quality` AS `jute_quality`,`vowsls`.`scm_mr_hdr`.`ac_year` AS `ac_year`,round(((`vowsls`.`scm_mr_line_item`.`accepted_weight` / 100) - `vowsls`.`scm_mr_line_item`.`weight_consumed`),0) AS `stock`,`vowsls`.`scm_mr_line_item`.`company_id` AS `company_id` from ((`vowsls`.`jute_quality_price_master` join `vowsls`.`scm_mr_line_item` on((`vowsls`.`jute_quality_price_master`.`item_code` = `vowsls`.`scm_mr_line_item`.`item_code`))) join `vowsls`.`scm_mr_hdr` on((`vowsls`.`scm_mr_hdr`.`jute_receive_no` = `vowsls`.`scm_mr_line_item`.`jute_receive_no`))) where (round(((`vowsls`.`scm_mr_line_item`.`accepted_weight` / 100) - `vowsls`.`scm_mr_line_item`.`weight_consumed`),0) > 0);;
CREATE OR REPLACE VIEW receipt_issue_ledger AS select `h`.`company_id` AS `company_id`,`h`.`ac_year` AS `ac_year`,`h`.`store_receive_dt` AS `date`,concat(`l`.`item_grp_id`,`l`.`item_code`) AS `itemcode`,`it`.`item_desc` AS `Itemdescription`,`l`.`store_receive_no` AS `store_receive_no`,`l`.`store_line_item_no` AS `store_line_item_no`,'' AS `issue_no`,`l`.`final_qty` AS `receipt`,'' AS `issue` from ((`vowsls`.`scm_sr_line_item` `l` left join `vowsls`.`scm_sr_hdr` `h` on((`l`.`store_receive_no` = `h`.`store_receive_no`))) left join `vowsls`.`itemmaster` `it` on(((`l`.`item_code` = `it`.`item_code`) and (`h`.`company_id` = `it`.`company_id`) and (`l`.`item_grp_id` = `it`.`group_code`)))) where ((`l`.`is_active` = 1) and (`h`.`sr_good_recept_status` <> 4)) union select `h`.`company_id` AS `company_id`,`h`.`fin_year` AS `ac_year`,`h`.`issue_date` AS `date`,concat(`h`.`group_code`,`h`.`item_code`) AS `itemcode`,`i`.`item_desc` AS `Itemdescription`,'' AS `receipt`,'' AS `store_receive_no`,`h`.`issue_no` AS `issue_no`,'' AS `store_line_item_no`,`h`.`issue_qty` AS `issue` from (`vowsls`.`scm_issue_hdr` `h` join `vowsls`.`itemmaster` `i`) where ((`h`.`company_id` = `i`.`company_id`) and (`h`.`group_code` = `i`.`group_code`) and (`h`.`item_code` = `i`.`item_code`) and (`h`.`is_active` = 1)) order by `date`;;
CREATE OR REPLACE VIEW request_hdr_view AS select `u`.`first_name` AS `created_by`,`l`.`issue_no` AS `issue_no`,`l`.`hdr_id` AS `hdr_id`,`l`.`sr_line_id` AS `sr_line_id`,`l`.`sr_no` AS `sr_no`,`l`.`company_id` AS `company_id`,`l`.`fin_year` AS `fin_year`,`bm`.`branch_name` AS `branch_name`,`pm`.`prj_name` AS `prj_name`,`l`.`issue_date` AS `issue_date`,`cm`.`name` AS `name`,`sm`.`status_name` AS `status_name`,`l`.`dept_id` AS `dept_id`,`md`.`dept_desc` AS `dept_desc`,`mm`.`mechine_name` AS `mechine_name`,`l`.`group_code` AS `group_code`,`igm`.`group_desc` AS `group_desc`,`l`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_desc`,`l`.`uom_code` AS `uom_code`,`l`.`issue_qty` AS `issue_qty`,`l`.`issue_value` AS `issue_value`,round((`l`.`issue_value` / `l`.`issue_qty`),2) AS `rate` from (((((((((`vowsls`.`scm_issue_hdr` `l` left join `vowsls`.`master_department` `md` on(((`md`.`mdept_id` = `l`.`dept_id`) and (`md`.`company_id` = `l`.`company_id`)))) left join `vowsls`.`item_group_master` `igm` on(((`igm`.`group_code` = `l`.`group_code`) and (`igm`.`company_id` = `l`.`company_id`)))) left join `vowsls`.`branch_master` `bm` on((`bm`.`branch_id` = `l`.`branch_id`))) left join `vowsls`.`project_master` `pm` on((`pm`.`prj_id` = `l`.`project_id`))) left join `vowsls`.`mechine_master` `mm` on((`mm`.`mechine_id` = `l`.`machine_id`))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `l`.`issue_status`))) left join `vowsls`.`customer_master` `cm` on((`cm`.`id` = `l`.`customer_id`))) left join `vowsls`.`itemmaster` `im` on(((`im`.`item_code` = `l`.`item_code`) and (`im`.`company_id` = `l`.`company_id`) and (`im`.`group_code` = `l`.`group_code`)))) left join `vowsls`.`user_details` `u` on((`u`.`email` = `l`.`created_by`))) where ((`l`.`issue_status` = 29) and (`l`.`is_active` = 1));;
CREATE OR REPLACE VIEW running_machine_report AS select `vowsls`.`daily_ebmc_attendance`.`company_id` AS `company_id`,`vowsls`.`mechine_master`.`mechine_id` AS `mechine_id`,`vowsls`.`daily_ebmc_attendance`.`spell` AS `spell`,`vowsls`.`mechine_master`.`dept_id` AS `dept_id`,`vowsls`.`mechine_master`.`mechine_name` AS `mechine_name`,`vowsls`.`mechine_master`.`type_of_mechine` AS `type_of_mechine`,`vowsls`.`mechine_master`.`type_of_m_c` AS `type_of_m_c`,`vowsls`.`mechine_master`.`prod_eff` AS `prod_eff` from (`vowsls`.`daily_ebmc_attendance` join `vowsls`.`mechine_master` on((`vowsls`.`daily_ebmc_attendance`.`mc_id` = `vowsls`.`mechine_master`.`mechine_id`))) where (`vowsls`.`daily_ebmc_attendance`.`attendace_date` = '2020-04-29');;
CREATE OR REPLACE VIEW sale_group_summary AS select `ili`.`item_group` AS `item_group`,`igm`.`group_desc` AS `group_desc`,`ili`.`uom` AS `uom`,round(sum(`ili`.`quantity`),2) AS `round(sum(ili.quantity),2)`,round(avg(`ili`.`rate`),0) AS `round(avg(ili.rate))` from (`vowsls`.`invoice_line_items` `ili` join `vowsls`.`item_group_master` `igm`);;
CREATE OR REPLACE VIEW sales_purchase_widget AS select `vowsls`.`month_wise_salepurchase`.`month` AS `month`,`vowsls`.`month_wise_salepurchase`.`salepurchase` AS `salepurchase`,`vowsls`.`month_wise_salepurchase`.`amount` AS `amount` from `vowsls`.`month_wise_salepurchase` union select `vowsls`.`month_wise_sales_widget`.`month` AS `month`,`vowsls`.`month_wise_sales_widget`.`salepurchase` AS `salepurchase`,`vowsls`.`month_wise_sales_widget`.`amount` AS `amount` from `vowsls`.`month_wise_sales_widget`;;
CREATE OR REPLACE VIEW sales_register_sitewise AS select `vowsls`.`bill_pass`.`company_id` AS `company_id`,`vowsls`.`bill_pass`.`fin_year` AS `ac_year`,`vowsls`.`bill_pass`.`bill_pass_trans_no` AS `billno`,cast(`vowsls`.`bill_pass`.`bill_date` as date) AS `billdate`,monthname(`vowsls`.`bill_pass`.`bill_date`) AS `billmonth`,year(`vowsls`.`bill_pass`.`bill_date`) AS `billyear`,`vowsls`.`branch_master`.`branch_name` AS `branch`,`vowsls`.`bill_pass`.`sale_type` AS `salestype`,ifnull(sum(`vowsls`.`bill_pass`.`c_tax`),0) AS `cgst`,ifnull(sum(`vowsls`.`bill_pass`.`i_tax`),0) AS `igst`,sum(`vowsls`.`bill_pass`.`net_amount`) AS `netamount`,`vowsls`.`suppliermaster`.`supp_name` AS `partyname` from ((`vowsls`.`bill_pass` join `vowsls`.`branch_master` on((`vowsls`.`bill_pass`.`branch_id` = `vowsls`.`branch_master`.`branch_id`))) join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`bill_pass`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`bill_pass`.`company_id`)))) group by `vowsls`.`bill_pass`.`company_id`,`ac_year`,`billno`,`billdate`,`billmonth`,`billyear`,`branch`,`salestype`,`partyname`;;
CREATE OR REPLACE VIEW sample_view AS select `a`.`company_id` AS `company_id`,`a`.`itemgroup` AS `itemgroup`,`a`.`value` AS `value`,`a`.`Stock` AS `stock` from (select `vowsls`.`view_store_consumption_categoryWise`.`company_id` AS `company_id`,`vowsls`.`view_store_consumption_categoryWise`.`itemgroup` AS `itemgroup`,'O' AS `value`,`vowsls`.`view_store_consumption_categoryWise`.`opening` AS `Stock` from `vowsls`.`view_store_consumption_categoryWise` union select `vowsls`.`view_store_consumption_categoryWise`.`company_id` AS `company_id`,`vowsls`.`view_store_consumption_categoryWise`.`itemgroup` AS `itemgroup`,'T' AS `value`,`vowsls`.`view_store_consumption_categoryWise`.`Transferred` AS `stock` from `vowsls`.`view_store_consumption_categoryWise` union select `vowsls`.`view_store_consumption_categoryWise`.`company_id` AS `company_id`,`vowsls`.`view_store_consumption_categoryWise`.`itemgroup` AS `itemgroup`,'I' AS `value`,`vowsls`.`view_store_consumption_categoryWise`.`issuevalue` AS `stock` from `vowsls`.`view_store_consumption_categoryWise` union select `vowsls`.`view_store_consumption_categoryWise`.`company_id` AS `company_id`,`vowsls`.`view_store_consumption_categoryWise`.`itemgroup` AS `itemgroup`,'R' AS `value`,`vowsls`.`view_store_consumption_categoryWise`.`returnvalue` AS `stock` from `vowsls`.`view_store_consumption_categoryWise` union select `vowsls`.`view_store_consumption_categoryWise`.`company_id` AS `company_id`,`vowsls`.`view_store_consumption_categoryWise`.`itemgroup` AS `itemgroup`,'C' AS `value`,`vowsls`.`view_store_consumption_categoryWise`.`closingvalue` AS `stock` from `vowsls`.`view_store_consumption_categoryWise`) `a`;;
CREATE OR REPLACE VIEW sr_hdr_view AS select `p`.`company_id` AS `company_id`,`cm`.`company_code` AS `Company Code`,`p`.`branch_id` AS `Branch Id`,`bm`.`branch_name` AS `Branch Name`,`p`.`project_id` AS `Project Id`,`pm`.`prj_name` AS `Project Name`,`l`.`gate_line_item_no` AS `gate_line_item_no`,`p`.`ac_year` AS `Ac Year`,`p`.`store_receive_no` AS `Sr No`,`p`.`store_receive_dt` AS `Sr_Date`,`p`.`sr_type` AS `Sr Type`,`su`.`supp_code` AS `Supp Code`,`su`.`supp_name` AS `Supplier`,`l`.`store_line_item_no` AS `Store Lineitem No`,`l`.`po_no` AS `Po Num`,`l`.`po_line_no` AS `Po Line No`,`p`.`sr_good_recept_status` AS `Status Id`,`sm`.`status_name` AS `status_name`,`l`.`item_grp_id` AS `Group Code`,`igm`.`group_desc` AS `Group Name`,`l`.`item_code` AS `Item Code`,`im`.`item_desc` AS `Item Desc`,`l`.`i_tax` AS `I Tax`,`l`.`c_tax` AS `C Tax`,`l`.`s_tax` AS `S Tax`,`l`.`final_qty` AS `Sr Quantity`,`l`.`quantity_consumed` AS `Consumed Quantity`,`l`.`stock_transer_quantity` AS `Transfer Quantity`,`l`.`rate` AS `Master Rate` from ((((((((`vowsls`.`scm_sr_hdr` `p` join `vowsls`.`scm_sr_line_item` `l` on(((`l`.`store_receive_no` = `p`.`store_receive_no`) and (`l`.`is_active` = 1)))) left join `vowsls`.`company_master` `cm` on((`cm`.`comp_id` = `p`.`company_id`))) left join `vowsls`.`branch_master` `bm` on((`bm`.`branch_id` = `p`.`branch_id`))) left join `vowsls`.`project_master` `pm` on((`pm`.`prj_id` = `p`.`project_id`))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `p`.`sr_good_recept_status`))) left join `vowsls`.`item_group_master` `igm` on(((`igm`.`group_code` = `l`.`item_grp_id`) and (`p`.`company_id` = `igm`.`company_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`item_code` = `l`.`item_code`) and (`im`.`group_code` = `l`.`item_grp_id`) and (`im`.`is_active` = 1) and (`im`.`company_id` = `p`.`company_id`)))) left join `vowsls`.`suppliermaster` `su` on(((`p`.`supp_code` = `su`.`supp_code`) and (`su`.`company_id` = `p`.`company_id`)))) where (`p`.`sr_type` = 'SR');;
CREATE OR REPLACE VIEW sr_wise_stock_view AS select `l`.`store_receive_no` AS `store_receive_no`,`i`.`group_code` AS `group_code`,`i`.`item_code` AS `item_code`,`i`.`item_desc` AS `item_desc`,`i`.`max_value` AS `max_limit`,`i`.`max_order_value` AS `min_limit`,cast(`h`.`store_receive_dt` as date) AS `store_receive_dt`,round(`l`.`quantity_consumed`,3) AS `consumed_quantity`,round((`l`.`final_qty` - `l`.`quantity_consumed`),3) AS `available_quantity`,round(`l`.`final_qty`,3) AS `final_quantity`,round((`l`.`final_qty` * `l`.`rate`),2) AS `final_value`,round((`l`.`quantity_consumed` * `l`.`rate`),2) AS `consumed_value`,round(((`l`.`final_qty` - `l`.`quantity_consumed`) * `l`.`rate`),2) AS `available_value`,`h`.`ac_year` AS `ac_year`,`h`.`company_id` AS `company_id` from ((`vowsls`.`scm_sr_hdr` `h` join `vowsls`.`scm_sr_line_item` `l`) join `vowsls`.`itemmaster` `i`) where ((`h`.`store_receive_no` = `l`.`store_receive_no`) and (`l`.`item_code` = `i`.`item_code`) and (`i`.`group_code` = `l`.`item_grp_id`) and ((`l`.`final_qty` - `l`.`quantity_consumed`) > 0) and (`h`.`company_id` = `i`.`company_id`));;
CREATE OR REPLACE VIEW stock_transfer_st04 AS select `h`.`company_id` AS `company_id`,`l`.`store_line_item_no` AS `store_line_item_no`,`l`.`item_grp_id` AS `item_grp_id`,`l`.`item_code` AS `item_code`,`g`.`group_desc` AS `group_desc`,`i`.`item_desc` AS `item_desc`,`l`.`final_qty` AS `final_qty`,`l`.`quantity_consumed` AS `quantity_consumed`,`i`.`uom_code` AS `uom_code`,`l`.`rate` AS `rate`,round(sum(`sih`.`issue_qty`),3) AS `issued`,`h`.`store_receive_dt` AS `receipt_date`,max(`sih`.`issue_date`) AS `last_issue` from ((((`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h` on(((`h`.`store_receive_no` = `l`.`store_receive_no`) and (`h`.`sr_type` = 'STR') and (`h`.`sr_good_recept_status` <> 4)))) join `vowsls`.`item_group_master` `g` on(((`l`.`item_grp_id` = `g`.`group_code`) and (`h`.`company_id` = `g`.`company_id`)))) join `vowsls`.`itemmaster` `i` on(((`l`.`item_grp_id` = `i`.`group_code`) and (`l`.`item_code` = `i`.`item_code`) and (`h`.`company_id` = `i`.`company_id`)))) left join `vowsls`.`scm_issue_hdr` `sih` on(((`l`.`item_grp_id` = `sih`.`group_code`) and (`l`.`item_code` = `sih`.`item_code`) and (`h`.`company_id` = `sih`.`company_id`) and (`l`.`store_line_item_no` = `sih`.`sr_line_id`) and (`sih`.`is_active` = 1)))) where (`l`.`is_active` = 1) group by `l`.`store_line_item_no`,`l`.`item_grp_id`,`l`.`item_code`,`g`.`group_desc`,`i`.`item_desc`,`l`.`final_qty`,`l`.`quantity_consumed`,`i`.`uom_code`,`l`.`rate`;;
CREATE OR REPLACE VIEW stock_view AS select `h`.`company_id` AS `company_id`,`l`.`item_grp_id` AS `item_grp_id`,`l`.`item_code` AS `item_code`,concat(`l`.`item_grp_id`,`l`.`item_code`) AS `itemuniqueno`,`g`.`group_desc` AS `group_desc`,`i`.`item_desc` AS `item_desc`,round(sum((`l`.`final_qty` - `l`.`quantity_consumed`)),3) AS `stockbal`,`i`.`uom_code` AS `uom_code`,round(sum((`l`.`rate` * (`l`.`final_qty` - `l`.`quantity_consumed`))),3) AS `stockvalue`,`h`.`store_receive_dt` AS `lastreceipt`,`sih`.`issue_date` AS `lastissue`,(to_days(curdate()) - to_days(max(`sih`.`issue_date`))) AS `no_issue_days` from ((((`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h` on((`h`.`store_receive_no` = `l`.`store_receive_no`))) join `vowsls`.`item_group_master` `g` on(((`l`.`item_grp_id` = `g`.`group_code`) and (`h`.`company_id` = `g`.`company_id`)))) join `vowsls`.`itemmaster` `i` on(((`l`.`item_grp_id` = `i`.`group_code`) and (`l`.`item_code` = `i`.`item_code`) and (`h`.`company_id` = `i`.`company_id`)))) left join `vowsls`.`scm_issue_hdr` `sih` on(((`l`.`item_grp_id` = `sih`.`group_code`) and (`l`.`item_code` = `sih`.`item_code`)))) where (round((`l`.`final_qty` - `l`.`quantity_consumed`),3) > 0) group by `h`.`company_id`,`l`.`item_grp_id`,`l`.`item_code`,`g`.`group_desc`,`i`.`item_desc`,`i`.`uom_code`,`lastreceipt`,`lastissue` order by `l`.`item_grp_id`,`l`.`item_code`;;
CREATE OR REPLACE VIEW store_consumption_value_quantity_report AS select `a`.`company` AS `company_id`,`a`.`ac_year` AS `ac_year`,`a`.`quantity` AS `quantity`,`a`.`val` AS `Value`,`a`.`itemcode` AS `itemcode`,`a`.`description` AS `description`,`a`.`unit` AS `unit`,`a`.`dat` AS `dat`,sum((case when (`a`.`dat` = 'January') then `a`.`quantity` else 0 end)) AS `JanQuantity`,sum((case when (`a`.`dat` = 'January') then `a`.`val` else 0 end)) AS `janValue`,sum((case when (`a`.`dat` = 'February') then `a`.`quantity` else 0 end)) AS `FebQuantity`,sum((case when (`a`.`dat` = 'February') then `a`.`val` else 0 end)) AS `Febvalue`,sum((case when (`a`.`dat` = 'March') then `a`.`quantity` else 0 end)) AS `MarQuantity`,sum((case when (`a`.`dat` = 'March') then `a`.`val` else 0 end)) AS `Marvalue`,sum((case when (`a`.`dat` = 'April') then `a`.`quantity` else 0 end)) AS `Aprquantity`,sum((case when (`a`.`dat` = 'April') then `a`.`val` else 0 end)) AS `aprvalue`,sum((case when (`a`.`dat` = 'May') then `a`.`quantity` else 0 end)) AS `Mayquantity`,sum((case when (`a`.`dat` = 'May') then `a`.`val` else 0 end)) AS `Mayvalue`,sum((case when (`a`.`dat` = 'June') then `a`.`quantity` else 0 end)) AS `Junquantity`,sum((case when (`a`.`dat` = 'June') then `a`.`val` else 0 end)) AS `Junval`,sum((case when (`a`.`dat` = 'July') then `a`.`quantity` else 0 end)) AS `Julquantity`,sum((case when (`a`.`dat` = 'July') then `a`.`val` else 0 end)) AS `Julvalue`,sum((case when (`a`.`dat` = 'August') then `a`.`quantity` else 0 end)) AS `Augquantity`,sum((case when (`a`.`dat` = 'August') then `a`.`val` else 0 end)) AS `augvalue`,sum((case when (`a`.`dat` = 'September') then `a`.`quantity` else 0 end)) AS `Sepquantity`,sum((case when (`a`.`dat` = 'September') then `a`.`quantity` else 0 end)) AS `Sepvalue`,sum((case when (`a`.`dat` = 'October') then `a`.`quantity` else 0 end)) AS `Octquantity`,sum((case when (`a`.`dat` = 'October') then `a`.`val` else 0 end)) AS `Octvalue`,sum((case when (`a`.`dat` = 'November') then `a`.`quantity` else 0 end)) AS `Novquantity`,sum((case when (`a`.`dat` = 'November') then `a`.`val` else 0 end)) AS `Novvalue`,sum((case when (`a`.`dat` = 'December') then `a`.`quantity` else 0 end)) AS `Decequantity`,sum((case when (`a`.`dat` = 'December') then `a`.`val` else 0 end)) AS `Decevalue` from (select `vowsls`.`scm_issue_hdr`.`company_id` AS `company`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `ac_year`,monthname(`vowsls`.`scm_issue_hdr`.`issue_date`) AS `dat`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_qty`),0) AS `quantity`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),0) AS `val`,concat(`vowsls`.`scm_issue_hdr`.`group_code`,`vowsls`.`scm_issue_hdr`.`item_code`) AS `itemcode`,`vowsls`.`itemmaster`.`item_desc` AS `description`,`vowsls`.`scm_issue_hdr`.`uom_code` AS `unit` from (`vowsls`.`scm_issue_hdr` join `vowsls`.`itemmaster` on(((`vowsls`.`scm_issue_hdr`.`company_id` = `vowsls`.`itemmaster`.`company_id`) and (`vowsls`.`scm_issue_hdr`.`item_code` = `vowsls`.`itemmaster`.`item_code`) and (`vowsls`.`scm_issue_hdr`.`group_code` = `vowsls`.`itemmaster`.`group_code`)))) group by `company`,`ac_year`,`dat`,`description`,`unit`,`itemcode`) `a` group by `a`.`company`,`a`.`ac_year`,`a`.`dat`,`a`.`description`,`a`.`unit`,`a`.`itemcode`;;
CREATE OR REPLACE VIEW store_month_wise_consumption AS select date_format(`vowsls`.`scm_issue_hdr`.`issue_date`,'%b') AS `month`,date_format(`vowsls`.`scm_issue_hdr`.`issue_date`,'%m') AS `monthno`,`vowsls`.`scm_issue_hdr`.`indent_type_id` AS `expense_type`,round(sum(`vowsls`.`scm_issue_hdr`.`issue_value`),2) AS `issue_value`,`vowsls`.`scm_issue_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` AS `fin_year` from `vowsls`.`scm_issue_hdr` group by date_format(`vowsls`.`scm_issue_hdr`.`issue_date`,'%b'),date_format(`vowsls`.`scm_issue_hdr`.`issue_date`,'%m'),`vowsls`.`scm_issue_hdr`.`indent_type_id`,`vowsls`.`scm_issue_hdr`.`company_id`,`vowsls`.`scm_issue_hdr`.`fin_year` order by `monthno`;;
CREATE OR REPLACE VIEW store_stock_report AS select `vowsls`.`view_store_line_item_wise_issue`.`company_id` AS `company_id`,`vowsls`.`view_store_line_item_wise_issue`.`item_grp_id` AS `item_grp_id`,`vowsls`.`view_store_line_item_wise_issue`.`item_code` AS `item_code`,concat(`vowsls`.`view_store_line_item_wise_issue`.`item_grp_id`,`vowsls`.`view_store_line_item_wise_issue`.`item_code`) AS `itemuniqueno`,`vowsls`.`view_store_line_item_wise_issue`.`group_desc` AS `group_desc`,`vowsls`.`view_store_line_item_wise_issue`.`item_desc` AS `item_desc`,`vowsls`.`view_store_line_item_wise_issue`.`uom_code` AS `uom_code`,round(sum((`vowsls`.`view_store_line_item_wise_issue`.`final_qty` - `vowsls`.`view_store_line_item_wise_issue`.`issued`)),3) AS `stockbal`,round(sum((`vowsls`.`view_store_line_item_wise_issue`.`rate` * (`vowsls`.`view_store_line_item_wise_issue`.`final_qty` - `vowsls`.`view_store_line_item_wise_issue`.`issued`))),3) AS `stockval`,max(`vowsls`.`view_store_line_item_wise_issue`.`receipt_date`) AS `lastreceipt`,max(`vowsls`.`view_store_line_item_wise_issue`.`last_issue`) AS `lastissue` from `vowsls`.`view_store_line_item_wise_issue` group by `vowsls`.`view_store_line_item_wise_issue`.`company_id`,`vowsls`.`view_store_line_item_wise_issue`.`item_grp_id`,`vowsls`.`view_store_line_item_wise_issue`.`item_code`,concat(`vowsls`.`view_store_line_item_wise_issue`.`item_grp_id`,`vowsls`.`view_store_line_item_wise_issue`.`item_code`),`vowsls`.`view_store_line_item_wise_issue`.`group_desc`,`vowsls`.`view_store_line_item_wise_issue`.`item_desc`,`vowsls`.`view_store_line_item_wise_issue`.`uom_code`;;
CREATE OR REPLACE VIEW storestockbal AS select `h`.`company_id` AS `company_id`,`l`.`item_grp_id` AS `item_grp_id`,`l`.`item_code` AS `item_code`,round(sum((`l`.`final_qty` - `l`.`quantity_consumed`)),3) AS `stockbal` from (`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h`) where ((`h`.`sr_good_recept_status` <> 4) and (`h`.`sr_good_recept_status` <> 6) and (`l`.`is_active` = 1) and (`l`.`store_receive_no` = `h`.`store_receive_no`) and ((`l`.`final_qty` - `l`.`quantity_consumed`) > 0)) group by `h`.`company_id`,`l`.`item_grp_id`,`l`.`item_code`;;
CREATE OR REPLACE VIEW str_hdr_view AS select `h`.`company_id` AS `company_id`,`h`.`ac_year` AS `ac_year`,`l`.`store_line_item_no` AS `STR Tran No`,`h`.`store_receive_no` AS `STR No`,`h`.`store_receive_dt` AS `store_receive_dt`,`sbm`.`branch_name` AS `Source Project`,`dbm`.`branch_name` AS `Project`,`sm`.`supp_name` AS `Source Supplier`,`st`.`status_name` AS `Status`,`l`.`src_line_id` AS `Source SR Tran No`,`l`.`src_sr_no` AS `Source SR No`,`l`.`final_qty` AS `STR Quantity`,`l`.`quantity_consumed` AS `STR Consumed Quantity`,`l`.`stock_transer_quantity` AS `STR Transfered Quantity`,`l`.`item_grp_id` AS `Group Code`,`igm`.`group_desc` AS `Group Name`,`l`.`item_code` AS `Item Code`,`im`.`item_desc` AS `Item Name`,`l`.`rate` AS `rate`,`l`.`i_tax` AS `i_tax`,`l`.`c_tax` AS `c_tax`,`l`.`s_tax` AS `s_tax` from (((((((`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h` on(((`l`.`store_receive_no` = `h`.`store_receive_no`) and (`h`.`sr_type` = 'STR')))) left join `vowsls`.`branch_master` `sbm` on((`sbm`.`branch_id` = `h`.`src_branch`))) left join `vowsls`.`branch_master` `dbm` on((`dbm`.`branch_id` = `h`.`des_branch`))) left join `vowsls`.`item_group_master` `igm` on(((`igm`.`group_code` = `l`.`item_grp_id`) and (`igm`.`company_id` = `h`.`company_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`item_code` = `l`.`item_code`) and (`im`.`company_id` = `h`.`company_id`) and (`im`.`group_code` = `l`.`item_grp_id`)))) left join `vowsls`.`suppliermaster` `sm` on(((`sm`.`supp_code` = `l`.`src_supplier_code`) and (`h`.`company_id` = `sm`.`company_id`)))) left join `vowsls`.`status_master` `st` on((`st`.`status_id` = `h`.`sr_good_recept_status`)));;
CREATE OR REPLACE VIEW supplier_Wise_Store_receipt AS select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,`vowsls`.`project_master`.`prj_name` AS `project`,`vowsls`.`branch_master`.`branch_name` AS `Branch`,`vowsls`.`suppliermaster`.`supp_name` AS `Supplier`,`vowsls`.`scm_sr_line_item`.`uom_code` AS `Unit`,cast(`vowsls`.`scm_sr_hdr`.`store_receive_dt` as date) AS `Date`,concat(`vowsls`.`scm_sr_line_item`.`item_grp_id`,`vowsls`.`scm_sr_line_item`.`item_code`) AS `Itemcode`,`vowsls`.`itemmaster`.`item_desc` AS `Description`,`vowsls`.`scm_sr_line_item`.`rate` AS `Rate`,`vowsls`.`scm_sr_hdr`.`store_print_no` AS `srprintno`,`vowsls`.`scm_sr_hdr`.`good_type` AS `goodtype`,`vowsls`.`scm_sr_hdr`.`gate_entry_no` AS `gateentryno`,cast(`vowsls`.`scm_sr_hdr`.`challan_date` as date) AS `challandate`,`vowsls`.`scm_sr_line_item`.`warehouse_no` AS `Warehouseno`,`vowsls`.`scm_sr_hdr`.`consignment_date` AS `consignmentdate`,`vowsls`.`scm_sr_hdr`.`consignment_no` AS `consignmentno`,`vowsls`.`scm_sr_hdr`.`vehicle_no` AS `vehicleno`,`vowsls`.`scm_sr_hdr`.`po_num` AS `poNo`,round(sum((`vowsls`.`scm_sr_line_item`.`rate` * `vowsls`.`scm_sr_line_item`.`final_qty`)),0) AS `Amount`,`vowsls`.`scm_sr_line_item`.`tax_percentage` AS `Tax`,round(sum(`vowsls`.`scm_sr_line_item`.`final_qty`),0) AS `Qauntity`,`vowsls`.`scm_sr_hdr`.`store_receive_no` AS `Number`,`vowsls`.`bill_pass`.`invoice_no` AS `Invoiceno` from ((((((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`itemmaster` on(((`vowsls`.`itemmaster`.`item_code` = `vowsls`.`scm_sr_line_item`.`item_code`) and (`vowsls`.`itemmaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`) and (`vowsls`.`itemmaster`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`)))) join `vowsls`.`suppliermaster` on(((`vowsls`.`suppliermaster`.`supp_code` = `vowsls`.`scm_sr_hdr`.`supp_code`) and (`vowsls`.`suppliermaster`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) join `vowsls`.`project_master` on(((`vowsls`.`project_master`.`prj_id` = `vowsls`.`scm_sr_hdr`.`project_id`) and (`vowsls`.`project_master`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) join `vowsls`.`branch_master` on(((`vowsls`.`branch_master`.`branch_id` = `vowsls`.`scm_sr_hdr`.`branch_id`) and (`vowsls`.`branch_master`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) join `vowsls`.`bill_pass` on(((`vowsls`.`bill_pass`.`sr_mr_num` = `vowsls`.`scm_sr_hdr`.`store_receive_no`) and (`vowsls`.`bill_pass`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) where (`vowsls`.`scm_sr_line_item`.`is_active` = 1) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`vowsls`.`itemmaster`.`item_desc`,`Supplier`,`Date`,`Number`,`vowsls`.`scm_sr_line_item`.`rate`,`Tax`,`project`,`Branch`,`Unit`,`srprintno`,`goodtype`,`gateentryno`,`challandate`,`Warehouseno`,`poNo`,`Itemcode`,`Invoiceno`;;
CREATE OR REPLACE VIEW supplier_year_wise_data AS select round(sum((`l`.`quantity` * `l`.`rate`)),0) AS `po_value`,`s`.`supp_code` AS `supp_code`,`s`.`company_id` AS `company_id`,round(sum((`sl`.`final_qty` * `sl`.`rate`)),0) AS `sr_value`,`p`.`fin_year` AS `fin_year`,round(sum(`t`.`funds_in_amount`),0) AS `round(SUM(t.funds_in_amount),0)`,round(sum(`t`.`paid_amount`),0) AS `round(SUM(t.paid_amount),0)` from ((((((`vowsls`.`suppliermaster` `s` left join `vowsls`.`scm_po_hdr` `p` on(((`p`.`supp_code` = `s`.`supp_code`) and (`p`.`company_id` = `s`.`company_id`)))) join `vowsls`.`scm_po_line_item` `l` on(((`l`.`po_num` = `p`.`po_num`) and (`l`.`is_active` = 1) and (`p`.`po_type` <> 'J')))) left join `vowsls`.`scm_sr_hdr` `sr` on(((`sr`.`supp_code` = `s`.`supp_code`) and (`sr`.`company_id` = `s`.`company_id`)))) join `vowsls`.`scm_sr_line_item` `sl` on(((`sl`.`store_receive_no` = `sr`.`store_receive_no`) and (`sl`.`is_active` = 1) and (`sr`.`ac_year` = `p`.`fin_year`)))) left join `vowsls`.`ledger_master` `lm` on(((`lm`.`suppl_id` = `s`.`supp_code`) and (`lm`.`company_id` = `s`.`company_id`)))) left join `vowsls`.`transactions` `t` on(((`t`.`ledger_id` = `lm`.`id`) and (`t`.`is_active` = 1) and (`t`.`transaction_type` = 'B') and (`t`.`transaction_status` = '3') and (`t`.`ac_year` = `p`.`fin_year`)))) group by `s`.`supp_code`,`p`.`fin_year`,`sr`.`ac_year`,`t`.`ac_year`,`s`.`company_id`;;
CREATE OR REPLACE VIEW tbl_view_proc_material_inventory AS select `tpid`.`item` AS `item`,`tpi`.`inward_id` AS `inward`,`tpid`.`indent_details_id` AS `inward_detail`,`tpi`.`store_receipt_no` AS `store_receipt_no`,`tpi`.`store_receipt_date` AS `store_receipt_date`,`tpid`.`rate` AS `actual_rate`,(case when (`tpid`.`discount_mode` = 1) then (((`tpid`.`accepted_qty` * `tpid`.`rate`) - `tpid`.`discount`) / `tpid`.`accepted_qty`) when (`tpid`.`discount_mode` = 2) then (`tpid`.`rate` - ((`tpid`.`rate` * `tpid`.`discount`) / 100)) else round(`tpid`.`rate`,2) end) AS `rate`,`tpid`.`discount_mode` AS `discount_mode`,`tpid`.`discount` AS `discount`,`tpid`.`accepted_qty` AS `qty`,ifnull(`sih`.`issueqty`,0) AS `issueqty`,round((`tpid`.`accepted_qty` - ifnull(`sih`.`issueqty`,0)),3) AS `balance_qty`,`tpi`.`company` AS `company`,`tpi`.`branch` AS `branch`,`tpi`.`project` AS `project`,`tpi`.`sr_status` AS `sr_status`,`tpid`.`wh_id` AS `wh_id`,`i`.`group_code` AS `group_code`,`i`.`item_code` AS `item_code`,`i`.`item_desc` AS `item_desc` from (((`vowsls`.`tbl_proc_inward` `tpi` join (select `tpp`.`srl_no` AS `srl_no`,`tpp`.`indent_details_id` AS `indent_details_id`,`tpp`.`dispatch_qty` AS `dispatch_qty`,`tpp`.`inward_qty` AS `inward_qty`,`tpp`.`uom` AS `uom`,`tpp`.`approved_qty` AS `approved_qty`,`tpp`.`rejected_qty` AS `rejected_qty`,`tpp`.`reasons` AS `reasons`,`tpp`.`source` AS `source`,`tpp`.`created_date` AS `created_date`,`tpp`.`created_by` AS `created_by`,`tpp`.`last_modified_by` AS `last_modified_by`,`tpp`.`last_modified_date` AS `last_modified_date`,`tpp`.`last_update` AS `last_update`,`tpp`.`tax_type` AS `tax_type`,`tpp`.`tax_name` AS `tax_name`,`tpp`.`tax_percentage` AS `tax_percentage`,`tpp`.`cgst_amount` AS `cgst_amount`,`tpp`.`igst_amount` AS `igst_amount`,`tpp`.`cgst_percentage` AS `cgst_percentage`,`tpp`.`igst_percentage` AS `igst_percentage`,`tpp`.`sgst_amount` AS `sgst_amount`,`tpp`.`sgst_percentage` AS `sgst_percentage`,`tpp`.`rate` AS `rate`,`tpp`.`amount` AS `amount`,`tpp`.`round_off_value` AS `round_off_value`,`tpp`.`discount_mode` AS `discount_mode`,`tpp`.`discount` AS `discount`,`tpp`.`wh_id` AS `wh_id`,`tpp`.`debitnote_sequence` AS `debitnote_sequence`,`tpp`.`debitnote_value` AS `debitnote_value`,`tpp`.`creditnote_value` AS `creditnote_value`,`tpp`.`debitnote_qty` AS `debitnote_qty`,`tpp`.`creditnote_qty` AS `creditnote_qty`,`tpp`.`debitnote_cgst_tax` AS `debitnote_cgst_tax`,`tpp`.`debitnote_igst_tax` AS `debitnote_igst_tax`,`tpp`.`creditnote_igst_percentage` AS `creditnote_igst_percentage`,`tpp`.`creditnote_cgst_percentage` AS `creditnote_cgst_percentage`,`tpp`.`debitnote_sgst_tax` AS `debitnote_sgst_tax`,`tpp`.`debitnote_sgst_percentage` AS `debitnote_sgst_percentage`,`tpp`.`creditnote_sgst_tax` AS `creditnote_sgst_tax`,`tpp`.`creditnote_sgst_percentage` AS `creditnote_sgst_percentage`,`tpp`.`debitnote_rate` AS `debitnote_rate`,`tpp`.`creditnote_rate` AS `creditnote_rate`,`tpp`.`metadata` AS `metadata`,`tpp`.`inspection_check` AS `inspection_check`,`tpp`.`description` AS `description`,`tpp`.`is_active` AS `is_active`,`tpp`.`item` AS `item`,`tpp`.`po` AS `po`,`tpp`.`po_detail` AS `po_detail`,`tpp`.`budget_head` AS `budget_head`,`tpp`.`tax` AS `tax`,`tpp`.`status` AS `status`,`tpp`.`inward` AS `inward`,`tpp`.`department` AS `department`,`tpp`.`ctax_amount` AS `ctax_amount`,`tpp`.`ctax_per` AS `ctax_per`,`tpp`.`stax_amount` AS `stax_amount`,`tpp`.`stax_per` AS `stax_per`,`tpp`.`itax_per` AS `itax_per`,`tpp`.`itax_amount` AS `itax_amount`,`tpp`.`hsn_code` AS `hsn_code`,`tpp`.`remarks` AS `remarks`,`tpp`.`make` AS `make`,`tpp`.`discounted_rate` AS `discounted_rate`,`tpp`.`discounted_amount` AS `discounted_amount`,ifnull(`dbt`.`quantity`,0) AS `drqty`,(`tpp`.`inward_qty` - ifnull(`dbt`.`quantity`,0)) AS `accepted_qty` from ((select `tpid`.`srl_no` AS `srl_no`,`tpid`.`indent_details_id` AS `indent_details_id`,`tpid`.`dispatch_qty` AS `dispatch_qty`,`tpid`.`inward_qty` AS `inward_qty`,`tpid`.`uom` AS `uom`,`tpid`.`approved_qty` AS `approved_qty`,`tpid`.`rejected_qty` AS `rejected_qty`,`tpid`.`reasons` AS `reasons`,`tpid`.`source` AS `source`,`tpid`.`created_date` AS `created_date`,`tpid`.`created_by` AS `created_by`,`tpid`.`last_modified_by` AS `last_modified_by`,`tpid`.`last_modified_date` AS `last_modified_date`,`tpid`.`last_update` AS `last_update`,`tpid`.`tax_type` AS `tax_type`,`tpid`.`tax_name` AS `tax_name`,`tpid`.`tax_percentage` AS `tax_percentage`,`tpid`.`cgst_amount` AS `cgst_amount`,`tpid`.`igst_amount` AS `igst_amount`,`tpid`.`cgst_percentage` AS `cgst_percentage`,`tpid`.`igst_percentage` AS `igst_percentage`,`tpid`.`sgst_amount` AS `sgst_amount`,`tpid`.`sgst_percentage` AS `sgst_percentage`,`tpid`.`rate` AS `rate`,`tpid`.`amount` AS `amount`,`tpid`.`round_off_value` AS `round_off_value`,`tpid`.`discount_mode` AS `discount_mode`,`tpid`.`discount` AS `discount`,`tpid`.`wh_id` AS `wh_id`,`tpid`.`debitnote_sequence` AS `debitnote_sequence`,`tpid`.`debitnote_value` AS `debitnote_value`,`tpid`.`creditnote_value` AS `creditnote_value`,`tpid`.`debitnote_qty` AS `debitnote_qty`,`tpid`.`creditnote_qty` AS `creditnote_qty`,`tpid`.`debitnote_cgst_tax` AS `debitnote_cgst_tax`,`tpid`.`debitnote_igst_tax` AS `debitnote_igst_tax`,`tpid`.`creditnote_igst_percentage` AS `creditnote_igst_percentage`,`tpid`.`creditnote_cgst_percentage` AS `creditnote_cgst_percentage`,`tpid`.`debitnote_sgst_tax` AS `debitnote_sgst_tax`,`tpid`.`debitnote_sgst_percentage` AS `debitnote_sgst_percentage`,`tpid`.`creditnote_sgst_tax` AS `creditnote_sgst_tax`,`tpid`.`creditnote_sgst_percentage` AS `creditnote_sgst_percentage`,`tpid`.`debitnote_rate` AS `debitnote_rate`,`tpid`.`creditnote_rate` AS `creditnote_rate`,`tpid`.`metadata` AS `metadata`,`tpid`.`inspection_check` AS `inspection_check`,`tpid`.`description` AS `description`,`tpid`.`is_active` AS `is_active`,`tpid`.`item` AS `item`,`tpid`.`po` AS `po`,`tpid`.`po_detail` AS `po_detail`,`tpid`.`budget_head` AS `budget_head`,`tpid`.`tax` AS `tax`,`tpid`.`status` AS `status`,`tpid`.`inward` AS `inward`,`tpid`.`department` AS `department`,`tpid`.`ctax_amount` AS `ctax_amount`,`tpid`.`ctax_per` AS `ctax_per`,`tpid`.`stax_amount` AS `stax_amount`,`tpid`.`stax_per` AS `stax_per`,`tpid`.`itax_per` AS `itax_per`,`tpid`.`itax_amount` AS `itax_amount`,`tpid`.`hsn_code` AS `hsn_code`,`tpid`.`remarks` AS `remarks`,`tpid`.`make` AS `make`,`tpid`.`discounted_rate` AS `discounted_rate`,`tpid`.`discounted_amount` AS `discounted_amount` from (`vowsls`.`tbl_proc_inward_detail` `tpid` left join `vowsls`.`tbl_proc_inward` `tpi` on((`tpid`.`inward` = `tpi`.`inward_id`))) where ((`tpi`.`sr_status` = 3) and (`tpid`.`is_active` = 1))) `tpp` left join (select `tpdcl`.`adjustment_detail_id` AS `adjustment_detail_id`,`tpdcl`.`adjustment` AS `adjustment`,`tpdcl`.`inward_detail_id` AS `inward_detail_id`,`tpdcl`.`debitnote_type` AS `debitnote_type`,`tpdcl`.`quantity` AS `quantity`,`tpdcl`.`rate` AS `rate`,`tpdcl`.`discount` AS `discount`,`tpdcl`.`cgst_tax_amount` AS `cgst_tax_amount`,`tpdcl`.`igst__tax_amount` AS `igst__tax_amount`,`tpdcl`.`sgst_tax_amount` AS `sgst_tax_amount`,`tpdcl`.`reason` AS `reason`,`tpdcl`.`is_active` AS `is_active` from (`vowsls`.`tbl_proc_debit_credit_lineitem` `tpdcl` left join `vowsls`.`tbl_proc_debit_credit_hdr` `tpdch` on((`tpdch`.`adjustment_id` = `tpdcl`.`adjustment`))) where ((`tpdcl`.`is_active` = 1) and (`tpdch`.`adjustment_status` = 3) and (`tpdcl`.`debitnote_type` = 2))) `dbt` on((`tpp`.`indent_details_id` = `dbt`.`inward_detail_id`)))) `tpid` on((`tpi`.`inward_id` = `tpid`.`inward`))) left join `vowsls`.`itemmaster` `i` on((`tpid`.`item` = `i`.`item_id`))) left join (select `sih`.`inward` AS `inward`,`sih`.`sr_line_id` AS `sr_line_id`,`sih`.`item_id` AS `item_id`,round(sum(`sih`.`issue_qty`),3) AS `issueqty` from `vowsls`.`scm_issue_hdr` `sih` where ((`sih`.`is_active` = 1) and (`sih`.`issue_status` not in (4,6))) group by `sih`.`inward`,`sih`.`sr_line_id`,`sih`.`item_id`) `sih` on(((`sih`.`inward` = `tpid`.`inward`) and (`sih`.`sr_line_id` = `tpid`.`indent_details_id`) and (`sih`.`item_id` = `tpid`.`item`)))) where ((`tpid`.`is_active` = 1) and (`tpi`.`sr_status` = 3) and (`tpi`.`record_type` = 'GRN'));;
CREATE OR REPLACE VIEW unissued_items AS select `l`.`store_receive_no` AS `store_receive_no`,`l`.`item_grp_id` AS `item_grp_id`,`l`.`item_code` AS `item_code`,`h`.`store_print_no` AS `SR NUM`,concat(`l`.`item_grp_id`,`l`.`item_code`) AS `ITEM CODE`,`g`.`group_desc` AS `GROUP DESCRIPTION`,`i`.`item_desc` AS `ITEM DESCRIPTION`,round(`l`.`rate`,2) AS `RATE`,round(`l`.`final_qty`,3) AS `QTY`,round((`l`.`final_qty` * `l`.`rate`),3) AS `STOCK VALUE`,`h`.`company_id` AS `company_id`,`h`.`store_receive_dt` AS `store_receive_dt` from (((`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h`) join `vowsls`.`item_group_master` `g`) join `vowsls`.`itemmaster` `i`) where ((`l`.`store_receive_no` = `h`.`store_receive_no`) and (`l`.`is_active` = 1) and (`l`.`quantity_consumed` < 0.01) and (`g`.`group_code` = `l`.`item_grp_id`) and (`i`.`item_code` = `l`.`item_code`) and (`i`.`group_code` = `g`.`group_code`) and (`g`.`company_id` = `h`.`company_id`) and (`i`.`company_id` = `h`.`company_id`));;
CREATE OR REPLACE VIEW vJute_supp_claim_analysis AS select `a`.`supp_code` AS `supp_code`,`a`.`supp_name` AS `supp_name`,cast(`a`.`jute_receive_dt` as date) AS `jute_receive_dt`,`a`.`company_id` AS `company_id`,count(0) AS `mr_count`,sum((case when (`a`.`Pass_count` > 0) then 1 else 0 end)) AS `pass_count`,(count(0) - sum((case when (`a`.`Pass_count` > 0) then 1 else 0 end))) AS `claim_count`,round(((sum((case when (`a`.`Pass_count` > 0) then 1 else 0 end)) / count(0)) * 100),2) AS `pass_per`,round((((count(0) - sum((case when (`a`.`Pass_count` > 0) then 1 else 0 end))) / count(0)) * 100),2) AS `claim_per` from (select `smh`.`company_id` AS `company_id`,`s`.`supp_name` AS `supp_name`,`smh`.`supp_code` AS `supp_code`,`smh`.`jute_receive_dt` AS `jute_receive_dt`,`smh`.`jute_receive_no` AS `jute_receive_no`,sum((case when (`smli`.`claim_quality` = 'PASS') then 1 else 0 end)) AS `Pass_count`,sum((case when (`smli`.`claim_quality` <> 'PASS') then 1 else 0 end)) AS `Fail_count` from (`vowsls`.`scm_mr_line_item` `smli` join (`vowsls`.`scm_mr_hdr` `smh` join `vowsls`.`suppliermaster` `s` on(((`s`.`supp_code` = `smh`.`supp_code`) and (`s`.`company_id` = `smh`.`company_id`))))) where ((`smh`.`supp_code` is not null) and (`smh`.`jute_receive_no` = `smli`.`jute_receive_no`)) group by `smh`.`company_id`,`s`.`supp_name`,`smh`.`supp_code`,`smh`.`jute_receive_dt`,`smh`.`jute_receive_no`) `a` group by `a`.`supp_code`,`a`.`jute_receive_dt`,`a`.`company_id`,`a`.`supp_name`;;
CREATE OR REPLACE VIEW view_Leave_type_wise_summary AS select `w`.`company_id` AS `Company ID`,`l`.`leave_to_date` AS `In Leave`,`lt`.`leave_type_description` AS `Leave Type`,count(`w`.`eb_id`) AS `leave Type Count` from ((`vowsls`.`worker_master` `w` join `vowsls`.`leave_transactions` `l` on((`w`.`eb_id` = `l`.`eb_id`))) join `vowsls`.`leave_types` `lt` on((`lt`.`leave_type_id` = `l`.`leave_type_id`))) group by `w`.`eb_id`,`w`.`company_id`,`l`.`leave_to_date`,`lt`.`leave_type_description` order by `lt`.`leave_type_description`;;
CREATE OR REPLACE VIEW view_branch_wise_salary_summary AS select `e`.`EMPLOYEEID` AS `Employee ID`,`e`.`AMOUNT` AS `salary`,`b`.`branch_name` AS `Branch Name` from (((`vowsls`.`tbl_pay_employee_payroll` `e` join `vowsls`.`tbl_pay_period` `p` on((`p`.`ID` = `e`.`PAYPERIOD_ID`))) join `vowsls`.`branch_master` `b` on((`b`.`branch_id` = `p`.`branch_id`))) join `vowsls`.`tbl_pay_components` `c` on((`c`.`ID` = `e`.`COMPONENT_ID`))) group by `e`.`EMPLOYEEID`,`e`.`AMOUNT`,`b`.`branch_name` order by `b`.`branch_name`;;
CREATE OR REPLACE VIEW view_emp_cate_wise_dept_wise_summary AS select `d`.`dept_code` AS `Department Code`,`d`.`dept_desc` AS `Department Name`,`c`.`cata_code` AS `Category Code`,`c`.`cata_desc` AS `Category Name`,`w`.`company_id` AS `company_id`,`w`.`eb_id` AS `No of employees` from ((`vowsls`.`worker_master` `w` join `vowsls`.`category_master` `c` on((`c`.`cata_id` = `w`.`cata_id`))) join `vowsls`.`department_master` `d` on((`d`.`dept_id` = `w`.`dept_id`))) group by `w`.`cata_id`,`w`.`dept_id`,`w`.`company_id`,`w`.`eb_id` order by `c`.`cata_desc`,`d`.`dept_desc`;;
CREATE OR REPLACE VIEW view_emp_department_wise_summary AS select `d`.`dept_code` AS `Department Code`,`m`.`dept_desc` AS `Department Name`,`w`.`company_id` AS `company_id`,count(`w`.`eb_id`) AS `No of Employees` from ((`vowsls`.`worker_master` `w` join `vowsls`.`department_master` `d` on((`d`.`dept_id` = `w`.`dept_id`))) join `vowsls`.`master_department` `m` on((`m`.`mdept_id` = `d`.`mdept_id`))) group by `d`.`dept_code`,`m`.`dept_desc`,`w`.`company_id` order by `m`.`dept_desc`;;
CREATE OR REPLACE VIEW view_emp_designation_wise_summary AS select `d`.`desig` AS `Designation`,`w`.`company_id` AS `company_id`,count(`w`.`eb_id`) AS `No of Employees` from (`vowsls`.`designation` `d` join `vowsls`.`worker_master` `w` on((`w`.`desg_id` = `d`.`id`))) group by `w`.`desg_id`,`w`.`company_id` order by `d`.`desig`;;
CREATE OR REPLACE VIEW view_emp_leaves_list AS select `l`.`company_id` AS `Company ID`,`l`.`eb_id` AS `Employee Id`,`w`.`worker_name` AS `Employee Name`,`l`.`leave_from_date` AS `Leave From`,`l`.`leave_to_date` AS `Leave TO` from (`vowsls`.`leave_transactions` `l` join `vowsls`.`worker_master` `w` on((`w`.`eb_id` = `l`.`eb_id`))) where (`w`.`company_id` = 1) order by `l`.`leave_from_date`;;
CREATE OR REPLACE VIEW view_emp_payscheme_wise_list AS select `w`.`eb_id` AS `Employee ID`,concat(`w`.`worker_name`,' ',`w`.`middle_name`,' ',`w`.`last_name`) AS `Employee Name`,`w`.`date_of_birth` AS `Date Of Birth`,`w`.`date_of_joining` AS `Date of Joining`,`w`.`company_id` AS `company_id`,`dm`.`dept_desc` AS `Department`,`d`.`desig` AS `Designation`,`s`.`NAME` AS `Pay Scheme Name` from ((((`vowsls`.`worker_master` `w` join `vowsls`.`department_master` `dm` on((`w`.`dept_id` = `dm`.`dept_id`))) join `vowsls`.`designation` `d` on((`w`.`desg_id` = `d`.`id`))) join `vowsls`.`tbl_pay_employee_payscheme` `p` on((`w`.`eb_id` = `p`.`EMPLOYEEID`))) join `vowsls`.`tbl_pay_scheme` `s` on((`p`.`PAY_SCHEME_ID` = `s`.`ID`))) group by `w`.`eb_id`,`w`.`worker_name`,`w`.`date_of_birth`,`w`.`date_of_joining`,`w`.`company_id`,`dm`.`dept_desc`,`d`.`desig`,`s`.`NAME` order by `dm`.`dept_desc`,`d`.`desig`,`s`.`NAME`;;
CREATE OR REPLACE VIEW view_emp_sub_dept_wise_desig_wise_summary AS select `d`.`dept_code` AS `Department Code`,`d`.`dept_desc` AS `Department Description`,`ds`.`desig` AS `Designation`,`w`.`company_id` AS `company_id`,count(`w`.`eb_id`) AS `No of Employees` from ((`vowsls`.`worker_master` `w` join `vowsls`.`department_master` `d` on((`d`.`dept_id` = `w`.`dept_id`))) join `vowsls`.`designation` `ds` on((`ds`.`id` = `w`.`desg_id`))) group by `w`.`dept_id`,`w`.`desg_id`,`w`.`company_id` order by `d`.`dept_desc`,`ds`.`desig`;;
CREATE OR REPLACE VIEW view_emp_sub_dept_wise_summary AS select `d`.`dept_code` AS `Department Code`,`d`.`dept_desc` AS `Department Name`,`w`.`company_id` AS `company_id`,count(`w`.`eb_id`) AS `No of Employees` from (`vowsls`.`worker_master` `w` join `vowsls`.`department_master` `d` on((`w`.`dept_id` = `d`.`dept_id`))) group by `w`.`dept_id`,`w`.`company_id` order by `d`.`dept_desc`;;
CREATE OR REPLACE VIEW view_emp_type_wise_summary AS select `c`.`cata_code` AS `Category Code`,`c`.`cata_desc` AS `Category Name`,`w`.`company_id` AS `company_id`,count(`w`.`cata_id`) AS `No of employees` from (`vowsls`.`category_master` `c` join `vowsls`.`worker_master` `w` on((`w`.`cata_id` = `c`.`cata_id`))) group by `w`.`cata_id`,`w`.`company_id` order by `c`.`cata_desc`;;
CREATE OR REPLACE VIEW view_emp_wise_leave_ledger AS select `l`.`leave_ledger_id` AS `leave_ledger_id`,`l`.`eb_id` AS `Employee Id`,concat(`w`.`worker_name`,' ',`w`.`middle_name`,' ',`w`.`last_name`) AS `Employee Name`,`l`.`company_id` AS `company_id`,`l`.`leaves_per_year` AS `leaves_per_year`,`l`.`max_leaves_per_month` AS `max_leaves_per_month`,`l`.`used_leaves` AS `used_leaves`,`l`.`carry_forward_status` AS `carry_forward_status`,`l`.`encashment_status` AS `encashment_status` from (`vowsls`.`leave_ledger` `l` join `vowsls`.`worker_master` `w` on((`w`.`eb_id` = `l`.`eb_id`))) group by `l`.`leave_ledger_id`,`l`.`eb_id`,`w`.`worker_name`,`l`.`company_id`,`l`.`leaves_per_year`,`l`.`max_leaves_per_month`,`l`.`used_leaves`,`l`.`carry_forward_status`,`l`.`encashment_status` order by `w`.`worker_name`;;
CREATE OR REPLACE VIEW view_emplist_onroll AS select `d`.`daily_atten_id` AS `daily_atten_id`,`d`.`attendance_date` AS `attendance_date`,`d`.`attendance_mark` AS `attendance_mark`,`d`.`company_id` AS `company_id`,`wm`.`worker_name` AS `worker_name` from (`vowsls`.`daily_attendance` `d` join `vowsls`.`worker_master` `wm` on((`wm`.`eb_id` = `d`.`eb_id`))) where ((`d`.`attendance_mark` = 'p') and (`d`.`company_id` = '1'));;
CREATE OR REPLACE VIEW view_employees_retiring_this_month AS select `vowsls`.`worker_master`.`eb_id` AS `eb_id`,`vowsls`.`worker_master`.`worker_name` AS `worker_name`,`vowsls`.`worker_master`.`retired_date` AS `retired_date`,`vowsls`.`worker_master`.`company_id` AS `company_id`,`vowsls`.`academic_years`.`year` AS `ac_year` from (`vowsls`.`worker_master` join `vowsls`.`academic_years`) where ((month(`vowsls`.`worker_master`.`retired_date`) = month(curdate())) and (`vowsls`.`academic_years`.`company_id` = `vowsls`.`worker_master`.`company_id`));;
CREATE OR REPLACE VIEW view_itemgroup_wise_summary_report AS select `h`.`company_id` AS `company_id`,`l`.`store_line_item_no` AS `store_line_item_no`,`l`.`item_grp_id` AS `item_grp_id`,`g`.`group_desc` AS `group_desc`,`l`.`final_qty` AS `final_qty`,`l`.`quantity_consumed` AS `quantity_consumed`,`l`.`rate` AS `rate`,round(sum(`sih`.`issue_qty`),3) AS `issued`,`h`.`store_receive_dt` AS `receipt_date` from (((`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h` on(((`h`.`store_receive_no` = `l`.`store_receive_no`) and (`h`.`sr_good_recept_status` <> 4)))) join `vowsls`.`item_group_master` `g` on(((`l`.`item_grp_id` = `g`.`group_code`) and (`h`.`company_id` = `g`.`company_id`)))) left join `vowsls`.`scm_issue_hdr` `sih` on(((`l`.`item_grp_id` = `sih`.`group_code`) and (`l`.`item_code` = `sih`.`item_code`) and (`h`.`company_id` = `sih`.`company_id`) and (`l`.`store_line_item_no` = `sih`.`sr_line_id`) and (`sih`.`is_active` = 1)))) where (`l`.`is_active` = 1) group by `l`.`item_grp_id`;;
CREATE OR REPLACE VIEW view_jute_issue_by_line_item_wise AS select `vowsls`.`jute_issue`.`stock_id` AS `stock_id`,`vowsls`.`jute_issue`.`company_id` AS `company_id`,`vowsls`.`jute_issue`.`bale_loose` AS `bale_loose`,sum(`vowsls`.`jute_issue`.`quantity`) AS `qty`,round(sum(`vowsls`.`jute_issue`.`total_weight`),2) AS `wt` from `vowsls`.`jute_issue` where ((`vowsls`.`jute_issue`.`company_id` = 1) and (`vowsls`.`jute_issue`.`is_active` = 1)) group by `vowsls`.`jute_issue`.`stock_id`,`vowsls`.`jute_issue`.`company_id`,`vowsls`.`jute_issue`.`bale_loose`;;
CREATE OR REPLACE VIEW view_jute_line_item_wise_issue AS select `h`.`company_id` AS `company_id`,`l`.`jute_line_item_no` AS `jute_line_item_no`,`l`.`item_code` AS `item_code`,`g`.`group_desc` AS `group_desc`,`i`.`item_desc` AS `item_desc`,`l`.`advised_quantity` AS `advised_quantity`,`l`.`quantity` AS `quantity`,`i`.`uom_code` AS `uom_code`,`l`.`rate` AS `rate`,round(sum(`sih`.`quantity`),3) AS `issued`,`h`.`jute_receive_dt` AS `receipt_date`,max(`sih`.`issue_date`) AS `last_issue` from ((((`vowsls`.`scm_mr_line_item` `l` join `vowsls`.`scm_mr_hdr` `h` on(((`h`.`jute_receive_no` = `l`.`jute_receive_no`) and (`h`.`mr_good_recept_status` <> 4)))) join `vowsls`.`item_group_master` `g` on(((`l`.`item_code` = `g`.`group_code`) and (`h`.`company_id` = `g`.`company_id`)))) join `vowsls`.`itemmaster` `i` on(((`l`.`item_code` = `i`.`group_code`) and (`l`.`item_code` = `i`.`item_code`) and (`h`.`company_id` = `i`.`company_id`)))) left join `vowsls`.`jute_issue` `sih` on(((`l`.`jute_line_item_no` = `sih`.`issue_no`) and (`h`.`company_id` = `sih`.`company_id`) and (`sih`.`is_active` = 1)))) where (`l`.`is_active` = 1) group by `l`.`jute_line_item_no`,`l`.`item_code`,`g`.`group_desc`,`i`.`item_desc`,`l`.`advised_quantity`,`l`.`quantity`,`i`.`uom_code`,`l`.`rate`;;
CREATE OR REPLACE VIEW view_jute_mr_in_stock AS select `vowsls`.`v`.`jute_receive_no` AS `jute_receive_no`,`h`.`jute_receive_dt` AS `jute_receive_dt`,`vowsls`.`v`.`mr_line_id` AS `mr_line_id`,`vowsls`.`v`.`mr_print_no` AS `mr_print_no`,`vowsls`.`v`.`unit_conversion` AS `unit_conversion`,`vowsls`.`v`.`branch_id` AS `branch_id`,`vowsls`.`v`.`quality_code` AS `quality_code`,`vowsls`.`v`.`quality_name` AS `quality_name`,`vowsls`.`v`.`rate` AS `rate`,`vowsls`.`v`.`godown` AS `godown`,`vowsls`.`v`.`godown_name` AS `godown_name`,`vowsls`.`v`.`company_id` AS `company_id`,sum(`vowsls`.`v`.`bales_receipt`) AS `receipt_bales`,sum(`vowsls`.`v`.`drums_receipt`) AS `receipt_drums`,sum(`vowsls`.`v`.`accepted_weight`) AS `receipt_weight`,round(((sum(`vowsls`.`v`.`bales_receipt`) - sum(`vowsls`.`v`.`bales_sold`)) - sum(`vowsls`.`v`.`bales_issued`)),2) AS `balestock`,round(((sum(`vowsls`.`v`.`drums_receipt`) - sum(`vowsls`.`v`.`drums_sold`)) - sum(`vowsls`.`v`.`drums_issued`)),2) AS `drumstock`,round(sum(((`vowsls`.`v`.`accepted_weight` - `vowsls`.`v`.`weight_sold`) - `vowsls`.`v`.`weight_issued`)),2) AS `weightstock` from (`vowsls`.`scm_mr_hdr` `h` left join `vowsls`.`view_jute_receipt_issue_sale` `v` on((`vowsls`.`v`.`jute_receive_no` = `h`.`jute_receive_no`))) where (`vowsls`.`v`.`status_name` <> 'REJECTED') group by `vowsls`.`v`.`jute_receive_no`,`h`.`jute_receive_dt`,`vowsls`.`v`.`mr_line_id`,`vowsls`.`v`.`mr_print_no`,`vowsls`.`v`.`unit_conversion`,`vowsls`.`v`.`branch_id`,`vowsls`.`v`.`quality_code`,`vowsls`.`v`.`rate`,`vowsls`.`v`.`godown`,`vowsls`.`v`.`godown_name`,`vowsls`.`v`.`quality_name` having ((round(((sum(`vowsls`.`v`.`bales_receipt`) - sum(`vowsls`.`v`.`bales_sold`)) - sum(`vowsls`.`v`.`bales_issued`)),2) <> 0) or (round(((sum(`vowsls`.`v`.`drums_receipt`) - sum(`vowsls`.`v`.`drums_sold`)) - sum(`vowsls`.`v`.`drums_issued`)),2) <> 0));;
CREATE OR REPLACE VIEW view_jute_receipt_issue_sale AS select `d`.`jute_receive_no` AS `jute_receive_no`,`d`.`company_id` AS `company_id`,`d`.`ac_year` AS `ac_year`,`d`.`tran_date` AS `tran_date`,`d`.`mr_print_no` AS `mr_print_no`,`d`.`tran_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`d`.`unit_conversion` AS `unit_conversion`,`d`.`branch_id` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,`d`.`mr_line_id` AS `mr_line_id`,`d`.`item_code` AS `item_code`,`d`.`quality_code` AS `quality_code`,`d`.`quality_name` AS `quality_name`,`d`.`uom` AS `uom`,`d`.`rate` AS `rate`,`d`.`godown` AS `godown`,`w`.`address` AS `godown_name`,`d`.`bales_receipt` AS `bales_receipt`,`d`.`bales_sold` AS `bales_sold`,`d`.`bales_issued` AS `bales_issued`,`d`.`drums_receipt` AS `drums_receipt`,`d`.`drums_sold` AS `drums_sold`,`d`.`drums_issued` AS `drums_issued`,`d`.`mill_weight` AS `mill_weight`,`d`.`accepted_weight` AS `accepted_weight`,`d`.`weight_sold` AS `weight_sold`,`d`.`weight_issued` AS `weight_issued`,`d`.`yarn_type_id` AS `yarn_type_id`,`d`.`yarn_type` AS `yarn_type`,`d`.`receipt_value` AS `receipt_value`,`d`.`issue_value` AS `issue_value`,`d`.`sale_value` AS `sale_value`,`d`.`transaction_type` AS `transaction_type` from ((((select `h`.`jute_receive_no` AS `jute_receive_no`,`h`.`company_id` AS `company_id`,`h`.`ac_year` AS `ac_year`,`h`.`jute_receive_dt` AS `tran_date`,`h`.`mr_print_no` AS `mr_print_no`,`h`.`mr_good_recept_status` AS `tran_status`,'' AS `status_name`,`h`.`unit_conversion` AS `unit_conversion`,`h`.`branch_id` AS `branch_id`,'' AS `branch_name`,`l`.`jute_line_item_no` AS `mr_line_id`,`l`.`item_code` AS `item_code`,`l`.`actual_quality` AS `quality_code`,`jpm`.`jute_quality` AS `quality_name`,`l`.`quantity_unit` AS `uom`,ifnull(`l`.`jute_issue_rate`,0) AS `rate`,`l`.`warehouse_no` AS `godown`,'' AS `godown_name`,ifnull(round(`l`.`actual_bale`,2),0) AS `bales_receipt`,'0' AS `bales_sold`,'0' AS `bales_issued`,ifnull(round(`l`.`actual_loose`,2),0) AS `drums_receipt`,'0' AS `drums_sold`,'0' AS `drums_issued`,ifnull(round(`l`.`actual_weight`,2),0) AS `mill_weight`,ifnull(round((`l`.`accepted_weight` / 100),2),0) AS `accepted_weight`,'0' AS `weight_sold`,'0' AS `weight_issued`,'' AS `yarn_type_id`,'' AS `yarn_type`,ifnull(round(((`l`.`jute_issue_rate` * `l`.`accepted_weight`) / 100),2),0) AS `receipt_value`,'0' AS `issue_value`,'0' AS `sale_value`,'R' AS `transaction_type` from ((`vowsls`.`scm_mr_line_item` `l` join `vowsls`.`scm_mr_hdr` `h` on((`h`.`jute_receive_no` = `l`.`jute_receive_no`))) left join `vowsls`.`jute_quality_price_master` `jpm` on((`jpm`.`id` = `l`.`actual_quality`))) where (`l`.`is_active` = 1) union select `i`.`mr_no` AS `jute_receive_no`,`i`.`company_id` AS `company_id`,`i`.`fin_year` AS `ac_year`,`i`.`issue_date` AS `tran_date`,`h`.`mr_print_no` AS `mr_print_no`,`i`.`issue_status` AS `tran_status`,'' AS `status_name`,`h`.`unit_conversion` AS `unit_conversion`,`h`.`branch_id` AS `branch_id`,'' AS `branch_name`,`i`.`stock_id` AS `mr_line_id`,`i`.`jute_type` AS `item_code`,`i`.`jute_quality` AS `quality_code`,`jpm`.`jute_quality` AS `quality_name`,'QNT' AS `uom`,ifnull(`l`.`jute_issue_rate`,0) AS `rate`,`l`.`warehouse_no` AS `godown`,'' AS `godown_name`,'0' AS `bales_receipt`,'0' AS `bales_sold`,(case when (`h`.`unit_conversion` = 'BALE') then ifnull(round(`i`.`quantity`,2),0) else 0 end) AS `bale_issued`,'0' AS `drums_receipt`,'0' AS `drums_sold`,(case when (`h`.`unit_conversion` = 'LOOSE') then ifnull(round(`i`.`quantity`,2),0) else 0 end) AS `drums_issued`,'0' AS `mill_weight`,'0' AS `accepted_weight`,'0' AS `weight_sold`,ifnull(round(`i`.`total_weight`,2),0) AS `weight_issued`,`i`.`yarn_type_id` AS `yarn_type_id`,`ytm`.`yarn_type` AS `yarn_type`,'0' AS `receipt_value`,ifnull(round((`l`.`jute_issue_rate` * `i`.`total_weight`),2),0) AS `issue_value`,'0' AS `sale_value`,'I' AS `transaction_type` from ((((`vowsls`.`jute_issue` `i` left join `vowsls`.`scm_mr_line_item` `l` on(((`l`.`jute_line_item_no` = `i`.`stock_id`) and (`l`.`is_active` = 1)))) left join `vowsls`.`scm_mr_hdr` `h` on(((`h`.`jute_receive_no` = `l`.`jute_receive_no`) and (`h`.`mr_good_recept_status` not in ('4','6'))))) left join `vowsls`.`jute_quality_price_master` `jpm` on((`jpm`.`id` = `i`.`jute_quality`))) left join `vowsls`.`yarn_type_master` `ytm` on((`ytm`.`yarn_type_id` = `i`.`yarn_type_id`))) where (`i`.`is_active` = 1) union select `ih`.`mr_id` AS `jute_receive_no`,`ih`.`company_id` AS `company_id`,`ih`.`ac_year` AS `ac_year`,`ih`.`invoice_date` AS `tran_date`,'' AS `mr_print_no`,`ih`.`status` AS `tran_status`,'' AS `status_name`,`ih`.`unit_conversion` AS `unit_conversion`,`ih`.`branch_id` AS `branch_id`,'' AS `branch_name`,`il`.`mr_line_id` AS `mr_line_id`,`il`.`item_id` AS `item_code`,`il`.`quality_id` AS `quality_code`,`il`.`quality_name` AS `quality_name`,'QNT' AS `uom`,ifnull(`l`.`jute_issue_rate`,0) AS `rate`,`l`.`warehouse_no` AS `godown`,'' AS `godown_name`,'0' AS `bales_receipt`,ifnull(round(`il`.`sales_bale`,2),0) AS `bales_sold`,'0' AS `bale_issued`,'0' AS `drums_receipt`,ifnull(round(`il`.`sales_drum`,2),0) AS `drums_sold`,'0' AS `drums_issued`,'0' AS `mill_weight`,'0' AS `accepted_weight`,ifnull(round(`il`.`sales_weight`,2),0) AS `weight_sold`,'0' AS `weight_issued`,'0' AS `yarn_type_id`,'0' AS `yarn_type`,'0' AS `receipt_value`,'0' AS `issue_value`,ifnull(round((`l`.`jute_issue_rate` * `il`.`sales_weight`),2),0) AS `sale_value`,'S' AS `transaction_type` from (((`vowsls`.`invoice_hdr` `ih` join `vowsls`.`invoice_line_items` `il` on((`il`.`invoice_id` = `ih`.`invoice_id`))) left join `vowsls`.`scm_mr_line_item` `l` on(((`l`.`jute_line_item_no` = `il`.`mr_line_id`) and (`l`.`is_active` = 1)))) left join `vowsls`.`scm_mr_hdr` `h` on(((`h`.`jute_receive_no` = `ih`.`mr_id`) and (`h`.`mr_good_recept_status` not in ('4','6'))))) where ((`il`.`is_active` = 1) and (`il`.`quality_id` > 0))) `d` left join `vowsls`.`status_master` `sm` on((`d`.`tran_status` = `sm`.`status_id`))) left join `vowsls`.`branch_master` `bm` on((`d`.`branch_id` = `bm`.`branch_id`))) left join `vowsls`.`warehouse_details` `w` on((`d`.`godown` = `w`.`id`)));;
CREATE OR REPLACE VIEW view_max_podate AS select `a`.`company_id` AS `company_id`,concat(`a`.`group code`,`a`.`item code`) AS `itemcd`,`a`.`mxpo` AS `mxpo`,`vowsls`.`b`.`Po No` AS `po no`,`a`.`mxdate` AS `mxdate`,`vowsls`.`b`.`Supplier Name` AS `supplier name`,`vowsls`.`b`.`Po Quantity` AS `po Quantity`,`vowsls`.`b`.`Master Rate` AS `master rate` from ((select `vowsls`.`po_hdr_view`.`company_id` AS `company_id`,`vowsls`.`po_hdr_view`.`Group Code` AS `group code`,`vowsls`.`po_hdr_view`.`Item Code` AS `item code`,max(`vowsls`.`po_hdr_view`.`PO_Date`) AS `mxdate`,max(`vowsls`.`po_hdr_view`.`Po No`) AS `mxpo` from `vowsls`.`po_hdr_view` group by `vowsls`.`po_hdr_view`.`company_id`,`vowsls`.`po_hdr_view`.`Group Code`,`vowsls`.`po_hdr_view`.`Item Code`) `a` join `vowsls`.`po_hdr_view` `b`) where ((`a`.`group code` = `vowsls`.`b`.`Group Code`) and (`a`.`item code` = `vowsls`.`b`.`Item Code`) and (`a`.`mxdate` = `vowsls`.`b`.`PO_Date`) and (`a`.`mxpo` = `vowsls`.`b`.`Po No`) and (`a`.`company_id` = `vowsls`.`b`.`company_id`));;
CREATE OR REPLACE VIEW view_minmax_stock AS select `a`.`company_id` AS `company_id`,concat(`a`.`group_code`,`a`.`item_code`) AS `itemcode`,`a`.`item_desc` AS `item_desc`,`a`.`uom_code` AS `uom_code`,`a`.`max_order_value` AS `min_qty`,`a`.`max_value` AS `max_qty`,ifnull(`b`.`stockbal`,0) AS `stockbal`,ifnull(`b`.`stockval`,0) AS `stockval`,`a`.`abcd_group` AS `abcd_group` from ((select `vowsls`.`itemmaster`.`company_id` AS `company_id`,`vowsls`.`itemmaster`.`group_code` AS `group_code`,`vowsls`.`itemmaster`.`item_code` AS `item_code`,`vowsls`.`itemmaster`.`abcd_group` AS `abcd_group`,`vowsls`.`itemmaster`.`item_desc` AS `item_desc`,`vowsls`.`itemmaster`.`uom_code` AS `uom_code`,`vowsls`.`itemmaster`.`max_order_value` AS `max_order_value`,`vowsls`.`itemmaster`.`max_value` AS `max_value` from `vowsls`.`itemmaster` where (`vowsls`.`itemmaster`.`abcd_group` is not null)) `a` left join (select `vowsls`.`store_stock_report`.`company_id` AS `company_id`,`vowsls`.`store_stock_report`.`item_grp_id` AS `item_grp_id`,`vowsls`.`store_stock_report`.`item_code` AS `item_code`,`vowsls`.`store_stock_report`.`itemuniqueno` AS `itemuniqueno`,`vowsls`.`store_stock_report`.`group_desc` AS `group_desc`,`vowsls`.`store_stock_report`.`item_desc` AS `item_desc`,`vowsls`.`store_stock_report`.`uom_code` AS `uom_code`,`vowsls`.`store_stock_report`.`stockbal` AS `stockbal`,`vowsls`.`store_stock_report`.`stockval` AS `stockval`,`vowsls`.`store_stock_report`.`lastreceipt` AS `lastreceipt`,`vowsls`.`store_stock_report`.`lastissue` AS `lastissue` from `vowsls`.`store_stock_report`) `b` on(((`a`.`group_code` = `b`.`item_grp_id`) and (`a`.`item_code` = `b`.`item_code`) and (`a`.`company_id` = `b`.`company_id`))));;
CREATE OR REPLACE VIEW view_month_birthday_list AS select `vowsls`.`worker_master`.`eb_id` AS `EB NO`,`vowsls`.`worker_master`.`worker_name` AS `Employee`,`vowsls`.`worker_master`.`date_of_birth` AS `Date Of Birth`,`vowsls`.`worker_master`.`branch_id` AS `Branch` from (`vowsls`.`worker_master` left join `vowsls`.`branch_master` on((`vowsls`.`branch_master`.`branch_id` = `vowsls`.`worker_master`.`branch_id`))) where ((`vowsls`.`worker_master`.`company_id` = 1) and (cast((`vowsls`.`worker_master`.`date_of_birth` + interval (year(now()) - year(`vowsls`.`worker_master`.`date_of_birth`)) year) as date) between cast((now() - interval weekday(now()) day) as date) and cast((now() + interval (6 - weekday(now())) day) as date))) order by date_format(`vowsls`.`worker_master`.`date_of_birth`,'%m-%d') desc;;
CREATE OR REPLACE VIEW view_mr_all_details AS select `h`.`jute_receive_no` AS `jute_receive_no`,`h`.`company_id` AS `company_id`,`h`.`ac_year` AS `ac_year`,`h`.`jute_receive_dt` AS `jute_receive_dt`,`h`.`mr_print_no` AS `mr_print_no`,`h`.`mr_good_recept_status` AS `mr_good_recept_status`,`sm`.`status_name` AS `status_name`,`h`.`unit_conversion` AS `unit_conversion`,`h`.`branch_id` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,`l`.`jute_line_item_no` AS `jute_line_item_no`,`l`.`item_code` AS `item_code`,`l`.`actual_quality` AS `actual_quality`,`jpm`.`jute_quality` AS `jute_quality`,`l`.`quantity_unit` AS `quantity_unit`,`l`.`quantity` AS `quantity`,ifnull(`l`.`rate`,0) AS `rate`,`l`.`warehouse_no` AS `warehouse_no`,`w`.`address` AS `address`,ifnull(round(`l`.`actual_bale`,2),0) AS `actual_bale`,ifnull(`il`.`sales_bale`,0) AS `sales_bale`,(case when (`h`.`unit_conversion` = 'BALE') then ifnull(round(sum(`i`.`quantity`),2),0) else 0 end) AS `bale_issued`,ifnull(round(`l`.`actual_loose`,2),0) AS `actual_loose`,ifnull(round(`il`.`sales_drum`,2),0) AS `sales_drum`,(case when (`h`.`unit_conversion` = 'LOOSE') then ifnull(round(sum(`i`.`quantity`),2),0) else 0 end) AS `drums_issued`,ifnull(round(`l`.`actual_weight`,2),0) AS `mill_weight`,ifnull(round((`l`.`accepted_weight` / 100),2),0) AS `accepted_weight`,ifnull(round(sum(`i`.`total_weight`),2),0) AS `weight_issued`,ifnull(round(sum(`il`.`sales_weight`),2),0) AS `weight_sold` from (((((((`vowsls`.`scm_mr_line_item` `l` join `vowsls`.`scm_mr_hdr` `h` on((`h`.`jute_receive_no` = `l`.`jute_receive_no`))) left join `vowsls`.`jute_issue` `i` on(((`l`.`jute_line_item_no` = `i`.`stock_id`) and (`i`.`is_active` = 1) and (`i`.`issue_status` not in ('4','6'))))) left join `vowsls`.`invoice_line_items` `il` on(((`il`.`mr_line_id` = `l`.`jute_line_item_no`) and (`il`.`is_active` = 1)))) left join `vowsls`.`status_master` `sm` on((`h`.`mr_good_recept_status` = `sm`.`status_id`))) left join `vowsls`.`branch_master` `bm` on((`h`.`branch_id` = `bm`.`branch_id`))) left join `vowsls`.`jute_quality_price_master` `jpm` on((`jpm`.`id` = `l`.`actual_quality`))) left join `vowsls`.`warehouse_details` `w` on((`w`.`id` = `l`.`warehouse_no`))) where (`l`.`is_active` = 1) group by `il`.`sales_bale`,`il`.`sales_drum`,`h`.`jute_receive_no`,`l`.`jute_line_item_no`,`l`.`actual_bale`,`l`.`bales_consumed`,`l`.`actual_loose`,`l`.`drums_consumed`,round((`l`.`accepted_weight` / 100),2),`l`.`weight_consumed`;;
CREATE OR REPLACE VIEW view_payscheme_wise_employee_summary AS select `w`.`eb_id` AS `eb_id`,`w`.`worker_name` AS `worker_name`,`w`.`date_of_birth` AS `Date Of Birth`,`w`.`date_of_joining` AS `Date of Joining`,`dm`.`dept_desc` AS `Department`,`d`.`desig` AS `Designation`,`s`.`NAME` AS `Pay Scheme Name`,`w`.`company_id` AS `company_id`,count(`w`.`eb_id`) AS `No of employees` from ((((`vowsls`.`worker_master` `w` join `vowsls`.`department_master` `dm` on((`w`.`dept_id` = `dm`.`dept_id`))) join `vowsls`.`designation` `d` on((`w`.`desg_id` = `d`.`id`))) join `vowsls`.`tbl_pay_employee_payscheme` `p` on((`w`.`eb_id` = `p`.`EMPLOYEEID`))) join `vowsls`.`tbl_pay_scheme` `s` on((`p`.`PAY_SCHEME_ID` = `s`.`ID`))) group by `w`.`eb_id`,`w`.`worker_name`,`w`.`date_of_birth`,`w`.`company_id`,`w`.`date_of_joining`,`dm`.`dept_desc`,`d`.`desig`,`s`.`NAME` order by `dm`.`dept_desc`,`d`.`desig`;;
CREATE OR REPLACE VIEW view_proc_po_hdr AS select `p`.`company` AS `company_id`,`u`.`first_name` AS `Created By`,`l`.`po_detail_id` AS `lineitemno`,`cm`.`company_code` AS `Company Code`,`l`.`indent` AS `Indent Tran No`,`sili`.`indent_detail_id` AS `Indent No`,round((`l`.`qty` * `l`.`rate`),2) AS `Value`,`p`.`branch` AS `Branch Id`,`bm`.`branch_name` AS `Branch Name`,`p`.`project` AS `Project Id`,`pm`.`name` AS `Project Name`,`ay`.`year` AS `Ac Year`,`p`.`po_sequence_no` AS `Po No`,cast(`p`.`po_approve_date` as date) AS `PO_Date`,`p`.`expected_delivery_date` AS `expected_date`,`su`.`supp_name` AS `Supplier Name`,`su`.`supp_code` AS `Supplier Code`,`p`.`status` AS `Status Id`,`sm`.`status_name` AS `status_name`,`im`.`group_code` AS `Group Code`,`igm`.`group_desc` AS `Group Name`,`im`.`item_code` AS `Item Code`,`im`.`item_desc` AS `Item Desc`,`l`.`qty` AS `Po Quantity`,`l`.`cancelled_qty` AS `PO Cancel Qty`,`sh`.`store_receipt_no` AS `SR No`,`sl`.`approved_qty` AS `Inward Quantity`,((`l`.`qty` - `sl`.`approved_qty`) - `l`.`cancelled_qty`) AS `Outst Quantity`,(to_days(curdate()) - to_days(`p`.`expected_delivery_date`)) AS `Exceeded Days`,`l`.`ctax_percentage` AS `C Tax`,`l`.`stax_percentage` AS `S tax`,`l`.`i_tax_percentage` AS `I Tax`,`l`.`rate` AS `Rate`,`l`.`rate_lastpurchase` AS `Last Po Rate`,`tpet`.`expense_type` AS `PO Type` from ((((((((((((((`vowsls`.`tbl_proc_po` `p` join `vowsls`.`tbl_proc_po_detail` `l` on(((`l`.`po` = `p`.`po_id`) and (`l`.`is_active` = 1)))) left join `vowsls`.`company_master` `cm` on((`cm`.`comp_id` = `p`.`company`))) left join `vowsls`.`branch_master` `bm` on((`bm`.`branch_id` = `p`.`branch`))) left join `vowsls`.`tbl_proc_project` `pm` on((`pm`.`project_id` = `p`.`project`))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `p`.`status`))) left join `vowsls`.`itemmaster` `im` on((`im`.`item_id` = `l`.`item`))) left join `vowsls`.`item_group_master` `igm` on((`im`.`group_code` = `igm`.`group_code`))) left join `vowsls`.`tbl_proc_indent_detail` `sili` on((`sili`.`indent_detail_id` = `l`.`indent_detail`))) left join `vowsls`.`suppliermaster` `su` on((`su`.`supp_id` = `p`.`supplier`))) left join `vowsls`.`user_details` `u` on((`u`.`user_id` = `p`.`created_by`))) left join `vowsls`.`tbl_proc_expense_type` `tpet` on((`p`.`category` = `tpet`.`id`))) left join `vowsls`.`academic_years` `ay` on(((`p`.`po_date` between `ay`.`from_date` and `ay`.`to_date`) and (`p`.`company` = `ay`.`company_id`)))) left join `vowsls`.`tbl_proc_inward_detail` `sl` on((`sl`.`po_detail` = `l`.`po_detail_id`))) left join `vowsls`.`tbl_proc_inward` `sh` on((`p`.`po_id` = `sh`.`po`))) where (`p`.`category` <> 1);;
CREATE OR REPLACE VIEW view_proc_store_line_item_wise_issue AS select `h`.`company` AS `company_id`,`h`.`branch` AS `branch_id`,`l`.`indent_details_id` AS `store_line_item_no`,`im`.`item_id` AS `item_id`,`im`.`group_code` AS `item_grp_id`,`im`.`item_code` AS `item_code`,`g`.`group_desc` AS `group_desc`,`im`.`item_desc` AS `item_desc`,`l`.`approved_qty` AS `final_qty`,(`tpmi`.`qty` - `tpmi`.`balanace_qty`) AS `quantity_consumed`,`im`.`uom_code` AS `uom_code`,`l`.`rate` AS `rate`,ifnull(round(`sih`.`issue_qty`,3),0) AS `issued`,`h`.`store_receipt_date` AS `receipt_date`,`sih`.`issue_date` AS `last_issue` from (((((`vowsls`.`tbl_proc_inward_detail` `l` join `vowsls`.`tbl_proc_inward` `h` on(((`h`.`inward_id` = `l`.`inward`) and (`h`.`sr_status` <> 4)))) join `vowsls`.`itemmaster` `im` on((`im`.`item_id` = `l`.`item`))) join `vowsls`.`item_group_master` `g` on((`im`.`group_code` = `g`.`group_code`))) left join `vowsls`.`tbl_proc_material_inventory` `tpmi` on((`tpmi`.`inward_detail` = `l`.`indent_details_id`))) left join (select `tpmi`.`inward_detail` AS `inward_detail`,round(sum(`sih`.`issue_qty`),3) AS `issue_qty`,max(`sih`.`issue_date`) AS `issue_date` from (`vowsls`.`scm_issue_hdr` `sih` left join `vowsls`.`tbl_proc_material_inventory` `tpmi` on((`tpmi`.`material_inventory_id` = `sih`.`material_inventory_id`))) where ((`sih`.`is_active` = 1) and (`sih`.`issue_status` <> 4)) group by `tpmi`.`inward_detail`) `sih` on((`l`.`indent_details_id` = `sih`.`inward_detail`))) where (`l`.`is_active` = 1);;
CREATE OR REPLACE VIEW view_proc_store_pending_inspection_quantity AS select `tpi`.`company` AS `company_id`,`tpi`.`branch` AS `branch_id`,`im`.`item_id` AS `item_id`,`im`.`group_code` AS `item_grp`,`im`.`item_code` AS `item_code`,round(sum(`gh`.`inward_qty`),4) AS `pending_inspection` from ((`vowsls`.`tbl_proc_inward_detail` `gh` join `vowsls`.`tbl_proc_inward` `tpi` on((`gh`.`inward` = `tpi`.`inward_id`))) left join `vowsls`.`itemmaster` `im` on((`gh`.`item` = `im`.`item_id`))) where (ifnull(`tpi`.`inspection_check`,'N') = 'N') group by `tpi`.`company`,`tpi`.`branch`,`im`.`group_code`,`im`.`item_id`,`im`.`item_code`;;
CREATE OR REPLACE VIEW view_proc_store_pending_to_receive_qty AS select `tpp`.`company` AS `company_id`,`tppd`.`po_detail_id` AS `line_item_num`,`im`.`group_code` AS `group_code`,`im`.`item_code` AS `item_code`,`tppd`.`qty` AS `po_qty`,ifnull(`tpid`.`received_qty`,0) AS `received_qty`,((`tppd`.`qty` - ifnull(`tpid`.`received_qty`,0)) - ifnull(`tppd`.`cancelled_qty`,0)) AS `pending_to_receive` from (((`vowsls`.`tbl_proc_po_detail` `tppd` join `vowsls`.`tbl_proc_po` `tpp` on((`tppd`.`po` = `tpp`.`po_id`))) left join (select `tpid`.`po_detail` AS `po_detail`,sum(`tpid`.`inward_qty`) AS `received_qty` from `vowsls`.`tbl_proc_inward_detail` `tpid` group by `tpid`.`po_detail`) `tpid` on((`tpid`.`po_detail` = `tppd`.`po_detail_id`))) left join `vowsls`.`itemmaster` `im` on((`tppd`.`item` = `im`.`item_id`))) where ((`tpp`.`category` not in (1,2)) and (((`tppd`.`qty` - ifnull(`tpid`.`received_qty`,0)) - ifnull(`tppd`.`cancelled_qty`,0)) > 0));;
CREATE OR REPLACE VIEW view_proc_store_po_not_raised AS select `tpi`.`company` AS `company_id`,`tpi`.`branch` AS `branch_id`,`im`.`item_id` AS `item_id`,`im`.`group_code` AS `group_code`,`im`.`item_code` AS `item_code`,round((sum(`tpid`.`qty`) - sum(`tpid`.`qty_po`)),2) AS `ind_pending_po` from ((`vowsls`.`tbl_proc_indent_detail` `tpid` join `vowsls`.`tbl_proc_indent` `tpi` on((`tpid`.`indent` = `tpi`.`indent_id`))) left join `vowsls`.`itemmaster` `im` on((`tpid`.`item` = `im`.`item_id`))) group by `tpi`.`company`,`tpi`.`branch`,`im`.`group_code`,`im`.`item_id`,`im`.`item_code` having (((sum(`tpid`.`qty`) - sum(ifnull(`tpid`.`qty_po`,0))) - sum(ifnull(`tpid`.`cancelled_qty`,0))) > 0);;
CREATE OR REPLACE VIEW view_proc_store_receipt_transfer_issue AS select `tpi`.`inward_id` AS `tran_hdr_id`,`tpid`.`indent_details_id` AS `tran_line_id`,`tpi`.`store_receipt_no` AS `sr_print_no`,`tpi`.`company` AS `company_id`,`ay`.`year` AS `ac_year`,`tpid`.`item` AS `item`,`im`.`group_code` AS `group_code`,`ig`.`group_desc` AS `group_name`,`im`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`im`.`uom_code` AS `uom_code`,substr(`tpi`.`store_receipt_date`,1,10) AS `tran_date`,`tpi`.`sr_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`tpi`.`branch` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'SR' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,`tpid`.`accepted_qty` AS `received_qty`,`tpid`.`rate` AS `rate`,'0' AS `transfer_in_qty`,'0' AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,(case when (`tpid`.`discount_mode` = 1) then ((((`tpid`.`accepted_qty` * `tpid`.`rate`) - `tpid`.`discount`) / `tpid`.`accepted_qty`) * `tpid`.`accepted_qty`) when (`tpid`.`discount_mode` = 2) then ((`tpid`.`rate` - ((`tpid`.`rate` * `tpid`.`discount`) / 100)) * `tpid`.`accepted_qty`) else round((`tpid`.`accepted_qty` * `tpid`.`rate`),2) end) AS `received_val`,'0' AS `transfer_in_val`,'0' AS `transfer_out_val` from ((((((`vowsls`.`tbl_proc_inward` `tpi` left join (select `tpp`.`srl_no` AS `srl_no`,`tpp`.`indent_details_id` AS `indent_details_id`,`tpp`.`dispatch_qty` AS `dispatch_qty`,`tpp`.`inward_qty` AS `inward_qty`,`tpp`.`uom` AS `uom`,`tpp`.`approved_qty` AS `approved_qty`,`tpp`.`rejected_qty` AS `rejected_qty`,`tpp`.`reasons` AS `reasons`,`tpp`.`source` AS `source`,`tpp`.`created_date` AS `created_date`,`tpp`.`created_by` AS `created_by`,`tpp`.`last_modified_by` AS `last_modified_by`,`tpp`.`last_modified_date` AS `last_modified_date`,`tpp`.`last_update` AS `last_update`,`tpp`.`tax_type` AS `tax_type`,`tpp`.`tax_name` AS `tax_name`,`tpp`.`tax_percentage` AS `tax_percentage`,`tpp`.`cgst_amount` AS `cgst_amount`,`tpp`.`igst_amount` AS `igst_amount`,`tpp`.`cgst_percentage` AS `cgst_percentage`,`tpp`.`igst_percentage` AS `igst_percentage`,`tpp`.`sgst_amount` AS `sgst_amount`,`tpp`.`sgst_percentage` AS `sgst_percentage`,`tpp`.`rate` AS `rate`,`tpp`.`amount` AS `amount`,`tpp`.`round_off_value` AS `round_off_value`,`tpp`.`discount_mode` AS `discount_mode`,`tpp`.`discount` AS `discount`,`tpp`.`wh_id` AS `wh_id`,`tpp`.`debitnote_sequence` AS `debitnote_sequence`,`tpp`.`debitnote_value` AS `debitnote_value`,`tpp`.`creditnote_value` AS `creditnote_value`,`tpp`.`debitnote_qty` AS `debitnote_qty`,`tpp`.`creditnote_qty` AS `creditnote_qty`,`tpp`.`debitnote_cgst_tax` AS `debitnote_cgst_tax`,`tpp`.`debitnote_igst_tax` AS `debitnote_igst_tax`,`tpp`.`creditnote_igst_percentage` AS `creditnote_igst_percentage`,`tpp`.`creditnote_cgst_percentage` AS `creditnote_cgst_percentage`,`tpp`.`debitnote_sgst_tax` AS `debitnote_sgst_tax`,`tpp`.`debitnote_sgst_percentage` AS `debitnote_sgst_percentage`,`tpp`.`creditnote_sgst_tax` AS `creditnote_sgst_tax`,`tpp`.`creditnote_sgst_percentage` AS `creditnote_sgst_percentage`,`tpp`.`debitnote_rate` AS `debitnote_rate`,`tpp`.`creditnote_rate` AS `creditnote_rate`,`tpp`.`metadata` AS `metadata`,`tpp`.`inspection_check` AS `inspection_check`,`tpp`.`description` AS `description`,`tpp`.`is_active` AS `is_active`,`tpp`.`item` AS `item`,`tpp`.`po` AS `po`,`tpp`.`po_detail` AS `po_detail`,`tpp`.`budget_head` AS `budget_head`,`tpp`.`tax` AS `tax`,`tpp`.`status` AS `status`,`tpp`.`inward` AS `inward`,`tpp`.`department` AS `department`,`tpp`.`ctax_amount` AS `ctax_amount`,`tpp`.`ctax_per` AS `ctax_per`,`tpp`.`stax_amount` AS `stax_amount`,`tpp`.`stax_per` AS `stax_per`,`tpp`.`itax_per` AS `itax_per`,`tpp`.`itax_amount` AS `itax_amount`,`tpp`.`hsn_code` AS `hsn_code`,`tpp`.`remarks` AS `remarks`,`tpp`.`make` AS `make`,`tpp`.`discounted_rate` AS `discounted_rate`,`tpp`.`discounted_amount` AS `discounted_amount`,ifnull(`dbt`.`quantity`,0) AS `drqty`,(`tpp`.`inward_qty` - ifnull(`dbt`.`quantity`,0)) AS `accepted_qty` from ((select `tpid`.`srl_no` AS `srl_no`,`tpid`.`indent_details_id` AS `indent_details_id`,`tpid`.`dispatch_qty` AS `dispatch_qty`,`tpid`.`inward_qty` AS `inward_qty`,`tpid`.`uom` AS `uom`,`tpid`.`approved_qty` AS `approved_qty`,`tpid`.`rejected_qty` AS `rejected_qty`,`tpid`.`reasons` AS `reasons`,`tpid`.`source` AS `source`,`tpid`.`created_date` AS `created_date`,`tpid`.`created_by` AS `created_by`,`tpid`.`last_modified_by` AS `last_modified_by`,`tpid`.`last_modified_date` AS `last_modified_date`,`tpid`.`last_update` AS `last_update`,`tpid`.`tax_type` AS `tax_type`,`tpid`.`tax_name` AS `tax_name`,`tpid`.`tax_percentage` AS `tax_percentage`,`tpid`.`cgst_amount` AS `cgst_amount`,`tpid`.`igst_amount` AS `igst_amount`,`tpid`.`cgst_percentage` AS `cgst_percentage`,`tpid`.`igst_percentage` AS `igst_percentage`,`tpid`.`sgst_amount` AS `sgst_amount`,`tpid`.`sgst_percentage` AS `sgst_percentage`,`tpid`.`rate` AS `rate`,`tpid`.`amount` AS `amount`,`tpid`.`round_off_value` AS `round_off_value`,`tpid`.`discount_mode` AS `discount_mode`,`tpid`.`discount` AS `discount`,`tpid`.`wh_id` AS `wh_id`,`tpid`.`debitnote_sequence` AS `debitnote_sequence`,`tpid`.`debitnote_value` AS `debitnote_value`,`tpid`.`creditnote_value` AS `creditnote_value`,`tpid`.`debitnote_qty` AS `debitnote_qty`,`tpid`.`creditnote_qty` AS `creditnote_qty`,`tpid`.`debitnote_cgst_tax` AS `debitnote_cgst_tax`,`tpid`.`debitnote_igst_tax` AS `debitnote_igst_tax`,`tpid`.`creditnote_igst_percentage` AS `creditnote_igst_percentage`,`tpid`.`creditnote_cgst_percentage` AS `creditnote_cgst_percentage`,`tpid`.`debitnote_sgst_tax` AS `debitnote_sgst_tax`,`tpid`.`debitnote_sgst_percentage` AS `debitnote_sgst_percentage`,`tpid`.`creditnote_sgst_tax` AS `creditnote_sgst_tax`,`tpid`.`creditnote_sgst_percentage` AS `creditnote_sgst_percentage`,`tpid`.`debitnote_rate` AS `debitnote_rate`,`tpid`.`creditnote_rate` AS `creditnote_rate`,`tpid`.`metadata` AS `metadata`,`tpid`.`inspection_check` AS `inspection_check`,`tpid`.`description` AS `description`,`tpid`.`is_active` AS `is_active`,`tpid`.`item` AS `item`,`tpid`.`po` AS `po`,`tpid`.`po_detail` AS `po_detail`,`tpid`.`budget_head` AS `budget_head`,`tpid`.`tax` AS `tax`,`tpid`.`status` AS `status`,`tpid`.`inward` AS `inward`,`tpid`.`department` AS `department`,`tpid`.`ctax_amount` AS `ctax_amount`,`tpid`.`ctax_per` AS `ctax_per`,`tpid`.`stax_amount` AS `stax_amount`,`tpid`.`stax_per` AS `stax_per`,`tpid`.`itax_per` AS `itax_per`,`tpid`.`itax_amount` AS `itax_amount`,`tpid`.`hsn_code` AS `hsn_code`,`tpid`.`remarks` AS `remarks`,`tpid`.`make` AS `make`,`tpid`.`discounted_rate` AS `discounted_rate`,`tpid`.`discounted_amount` AS `discounted_amount` from (`vowsls`.`tbl_proc_inward_detail` `tpid` left join `vowsls`.`tbl_proc_inward` `tpi` on((`tpid`.`inward` = `tpi`.`inward_id`))) where ((`tpi`.`sr_status` = 3) and (`tpid`.`is_active` = 1))) `tpp` left join (select `tpdcl`.`adjustment_detail_id` AS `adjustment_detail_id`,`tpdcl`.`adjustment` AS `adjustment`,`tpdcl`.`inward_detail_id` AS `inward_detail_id`,`tpdcl`.`debitnote_type` AS `debitnote_type`,`tpdcl`.`quantity` AS `quantity`,`tpdcl`.`rate` AS `rate`,`tpdcl`.`discount` AS `discount`,`tpdcl`.`cgst_tax_amount` AS `cgst_tax_amount`,`tpdcl`.`igst__tax_amount` AS `igst__tax_amount`,`tpdcl`.`sgst_tax_amount` AS `sgst_tax_amount`,`tpdcl`.`reason` AS `reason`,`tpdcl`.`is_active` AS `is_active` from (`vowsls`.`tbl_proc_debit_credit_lineitem` `tpdcl` left join `vowsls`.`tbl_proc_debit_credit_hdr` `tpdch` on((`tpdch`.`adjustment_id` = `tpdcl`.`adjustment`))) where ((`tpdcl`.`is_active` = 1) and (`tpdch`.`adjustment_status` = 3) and (`tpdcl`.`debitnote_type` = 2))) `dbt` on((`tpp`.`indent_details_id` = `dbt`.`inward_detail_id`)))) `tpid` on((`tpi`.`inward_id` = `tpid`.`inward`))) left join `vowsls`.`itemmaster` `im` on((`tpid`.`item` = `im`.`item_id`))) left join `vowsls`.`item_group_master` `ig` on(((`im`.`group_code` = `ig`.`group_code`) and (`ig`.`company_id` = `tpi`.`company`)))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `tpi`.`sr_status`))) left join `vowsls`.`branch_master` `bm` on((`tpi`.`branch` = `bm`.`branch_id`))) left join `vowsls`.`academic_years` `ay` on(((`tpi`.`store_receipt_actual_date` between `ay`.`from_date` and `ay`.`to_date`) and (`ay`.`company_id` = `tpi`.`company`)))) where (`tpid`.`is_active` = 1) union all select `ih`.`issue_no` AS `tran_hdr_id`,`ih`.`sr_line_id` AS `tran_line_id`,`tpi`.`store_receipt_no` AS `sr_print_no`,`ih`.`company_id` AS `company_id`,`ih`.`fin_year` AS `ac_year`,`ih`.`item_id` AS `item`,`im`.`group_code` AS `group_code`,`ig`.`group_desc` AS `group_name`,`im`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`ih`.`uom_code` AS `uom_code`,`ih`.`issue_date` AS `tran_date`,`ih`.`issue_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`ih`.`branch_id` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'I' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,'0' AS `received_qty`,`tpid`.`rate` AS `rate`,'0' AS `transfer_in_qty`,'0' AS `transfer_out_qty`,`ih`.`issue_qty` AS `issued_qty`,(case when (`tpid`.`discount_mode` = 1) then ((((`tpid`.`approved_qty` * `tpid`.`rate`) - `tpid`.`discount`) / `tpid`.`approved_qty`) * `ih`.`issue_qty`) when (`tpid`.`discount_mode` = 2) then ((`tpid`.`rate` - ((`tpid`.`rate` * `tpid`.`discount`) / 100)) * `ih`.`issue_qty`) else round((`ih`.`issue_qty` * `tpid`.`rate`),2) end) AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,'0' AS `received_val`,'0' AS `transfer_in_val`,'0' AS `transfer_out_val` from ((((((`vowsls`.`scm_issue_hdr` `ih` left join `vowsls`.`tbl_proc_inward` `tpi` on((`ih`.`inward` = `tpi`.`inward_id`))) left join `vowsls`.`tbl_proc_inward_detail` `tpid` on(((`ih`.`sr_line_id` = `tpid`.`indent_details_id`) and (`tpid`.`inward` = `tpi`.`inward_id`)))) left join `vowsls`.`itemmaster` `im` on((`ih`.`item_id` = `im`.`item_id`))) left join `vowsls`.`item_group_master` `ig` on(((`ig`.`group_code` = `im`.`group_code`) and (`ig`.`company_id` = `ih`.`company_id`)))) left join `vowsls`.`branch_master` `bm` on((`ih`.`branch_id` = `bm`.`branch_id`))) left join `vowsls`.`status_master` `sm` on((`ih`.`issue_status` = `sm`.`status_id`))) where (`ih`.`is_active` = 1) union all select `tpp`.`po_id` AS `tran_hdr_id`,`tppd`.`po_detail_id` AS `tran_line_id`,`tpp`.`po_sequence_no` AS `sr_print_no`,`tpp`.`company` AS `company_id`,`ay`.`year` AS `ac_year`,`tppd`.`item` AS `item`,`im`.`group_code` AS `group_code`,`ig`.`group_desc` AS `group_name`,`im`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`tppd`.`uom_code` AS `uom_code`,`tpp`.`po_approve_date` AS `tran_date`,`tpp`.`status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`tpp`.`branch` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'PO' AS `tran_type`,`tppd`.`qty` AS `ordered_qty`,`tppd`.`rate` AS `ordered_rate`,'0' AS `received_qty`,'0' AS `rate`,'0' AS `transfer_in_qty`,'0' AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,round((`tppd`.`qty` * `tppd`.`rate`),0) AS `ordered_val`,'0' AS `received_val`,'0' AS `transfer_in_val`,'0' AS `transfer_out_val` from ((((((`vowsls`.`tbl_proc_po` `tpp` left join `vowsls`.`tbl_proc_po_detail` `tppd` on((`tpp`.`po_id` = `tppd`.`po`))) left join `vowsls`.`itemmaster` `im` on((`tppd`.`item` = `im`.`item_id`))) left join `vowsls`.`item_group_master` `ig` on(((`im`.`group_code` = `ig`.`group_code`) and (`ig`.`company_id` = `tpp`.`company`)))) left join `vowsls`.`branch_master` `bm` on((`tpp`.`branch` = `bm`.`branch_id`))) left join `vowsls`.`status_master` `sm` on((`tpp`.`status` = `sm`.`status_id`))) left join `vowsls`.`academic_years` `ay` on(((`tpp`.`po_approve_date` between `ay`.`from_date` and `ay`.`to_date`) and (`ay`.`company_id` = `tpp`.`company`)))) where (`tppd`.`is_active` = 1);;
CREATE OR REPLACE VIEW view_proc_store_stock_report AS select `vowsls`.`view_proc_store_line_item_wise_issue`.`company_id` AS `company_id`,`vowsls`.`view_proc_store_line_item_wise_issue`.`branch_id` AS `branch_id`,`vowsls`.`view_proc_store_line_item_wise_issue`.`item_id` AS `item_id`,`vowsls`.`view_proc_store_line_item_wise_issue`.`item_grp_id` AS `item_grp_id`,`vowsls`.`view_proc_store_line_item_wise_issue`.`item_code` AS `item_code`,concat(`vowsls`.`view_proc_store_line_item_wise_issue`.`item_grp_id`,`vowsls`.`view_proc_store_line_item_wise_issue`.`item_code`) AS `itemuniqueno`,`vowsls`.`view_proc_store_line_item_wise_issue`.`group_desc` AS `group_desc`,`vowsls`.`view_proc_store_line_item_wise_issue`.`item_desc` AS `item_desc`,`vowsls`.`view_proc_store_line_item_wise_issue`.`uom_code` AS `uom_code`,round(sum((`vowsls`.`view_proc_store_line_item_wise_issue`.`final_qty` - `vowsls`.`view_proc_store_line_item_wise_issue`.`issued`)),3) AS `stockbal`,round(sum((`vowsls`.`view_proc_store_line_item_wise_issue`.`rate` * (`vowsls`.`view_proc_store_line_item_wise_issue`.`final_qty` - `vowsls`.`view_proc_store_line_item_wise_issue`.`issued`))),3) AS `stockval`,max(`vowsls`.`view_proc_store_line_item_wise_issue`.`receipt_date`) AS `lastreceipt`,max(`vowsls`.`view_proc_store_line_item_wise_issue`.`last_issue`) AS `lastissue` from `vowsls`.`view_proc_store_line_item_wise_issue` group by `vowsls`.`view_proc_store_line_item_wise_issue`.`company_id`,`vowsls`.`view_proc_store_line_item_wise_issue`.`branch_id`,`vowsls`.`view_proc_store_line_item_wise_issue`.`item_id`,`vowsls`.`view_proc_store_line_item_wise_issue`.`item_grp_id`,`vowsls`.`view_proc_store_line_item_wise_issue`.`item_code`,concat(`vowsls`.`view_proc_store_line_item_wise_issue`.`item_grp_id`,`vowsls`.`view_proc_store_line_item_wise_issue`.`item_code`),`vowsls`.`view_proc_store_line_item_wise_issue`.`group_desc`,`vowsls`.`view_proc_store_line_item_wise_issue`.`item_desc`,`vowsls`.`view_proc_store_line_item_wise_issue`.`uom_code`;;
CREATE OR REPLACE VIEW view_proc_waiting_po AS select `b`.`company_id` AS `company_id`,`a`.`indent_no` AS `indent_no`,`a`.`indent_srl_no` AS `indent_srl_no`,`a`.`fin_year` AS `fin_year`,`b`.`indent_date` AS `indent_date`,`a`.`group_code` AS `Group_code`,`a`.`item_code` AS `item_code`,`c`.`item_desc` AS `item_desc`,`a`.`indqty` AS `indqty`,`a`.`cancqty` AS `cancqty`,`a`.`poqty` AS `poqty`,((`a`.`indqty` - `a`.`poqty`) - `a`.`cancqty`) AS `balqty` from (((select `ind`.`indent_srl_no` AS `indent_srl_no`,`ind`.`indent_no` AS `indent_no`,`ind`.`fin_year` AS `fin_year`,`ind`.`group_code` AS `group_code`,`ind`.`item_code` AS `item_code`,`ind`.`indqty` AS `indqty`,`ind`.`cancqty` AS `cancqty`,ifnull(`ord`.`poqty`,0) AS `poqty` from ((select `vowsls`.`scm_indent_line_item`.`indent_srl_no` AS `indent_srl_no`,`vowsls`.`scm_indent_line_item`.`indent_no` AS `indent_no`,`vowsls`.`scm_indent_line_item`.`fin_year` AS `fin_year`,`vowsls`.`scm_indent_line_item`.`group_code` AS `group_code`,`vowsls`.`scm_indent_line_item`.`item_code` AS `item_code`,`vowsls`.`scm_indent_line_item`.`indent_qty` AS `indqty`,ifnull(`vowsls`.`scm_indent_line_item`.`cancel_qty`,0) AS `cancqty` from `vowsls`.`scm_indent_line_item`) `ind` left join (select `vowsls`.`scm_po_line_item`.`indent_no` AS `indent_no`,sum((`vowsls`.`scm_po_line_item`.`quantity` - ifnull(`vowsls`.`scm_po_line_item`.`cancel_qty`,0))) AS `poqty` from `vowsls`.`scm_po_line_item` group by `vowsls`.`scm_po_line_item`.`indent_no`) `ord` on((`ind`.`indent_srl_no` = `ord`.`indent_no`)))) `a` join `vowsls`.`scm_indent_hdr` `b`) join `vowsls`.`itemmaster` `c`) where ((`a`.`indent_no` = `b`.`indent_no`) and (`a`.`fin_year` = `b`.`fin_year`) and ((`b`.`indent_type` = 'M') or (`b`.`indent_type` = 'G') or (`b`.`indent_type` = 'C') or (`b`.`indent_type` = 'P') or (`b`.`indent_type` = 'H')) and (`a`.`indqty` > `a`.`poqty`) and (`a`.`group_code` = `c`.`group_code`) and (`a`.`item_code` = `c`.`item_code`) and (`c`.`company_id` = `b`.`company_id`)) order by `a`.`indent_srl_no`;;
CREATE OR REPLACE VIEW view_sr_register AS select `s`.`company_id` AS `company_id`,`s`.`ac_year` AS `ac_year`,`ss`.`store_receive_no` AS `store_receive_no`,`s`.`store_print_no` AS `store_print_no`,cast(`s`.`store_receive_dt` as date) AS `store_receive_dt`,`sm`.`supp_name` AS `supp_name`,`s`.`challan_no` AS `challan_no`,`st`.`status_name` AS `status_name`,(case when (`s`.`sr_good_recept_status` <> 4) then round((sum(`ss`.`amount_with_tax`) + `s`.`tcs_amount`),0) else '0' end) AS `bill_amount` from (((`vowsls`.`scm_sr_hdr` `s` join `vowsls`.`scm_sr_line_item` `ss`) join `vowsls`.`suppliermaster` `sm`) join `vowsls`.`status_master` `st`) where ((`s`.`store_receive_no` = `ss`.`store_receive_no`) and (`ss`.`is_active` = 1) and (`sm`.`supp_code` = `s`.`supp_code`) and (`sm`.`company_id` = `s`.`company_id`) and (`s`.`sr_good_recept_status` = `st`.`status_id`)) group by `ss`.`store_receive_no`,`sm`.`supp_name`;;
CREATE OR REPLACE VIEW view_store_consumption_categoryWise AS select `a`.`company_id` AS `company_id`,`a`.`ac_year` AS `ac_year`,`a`.`opening` AS `opening`,`a`.`Transferred` AS `Transferred`,`a`.`itemgroup` AS `itemgroup`,`a`.`issuevalue` AS `issuevalue`,`a`.`returnvalue` AS `returnvalue`,(((`a`.`opening` + `a`.`returnvalue`) - `a`.`issuevalue`) - `a`.`Transferred`) AS `closingvalue` from (select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,`vowsls`.`scm_sr_hdr`.`ac_year` AS `ac_year`,round(sum((((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_sr_line_item`.`stock_transer_quantity`) - `vowsls`.`scm_sr_line_item`.`quantity_consumed`) * `vowsls`.`scm_sr_line_item`.`rate`)),2) AS `opening`,round(sum((`vowsls`.`scm_sr_line_item`.`stock_transer_quantity` * `vowsls`.`scm_sr_line_item`.`rate`)),0) AS `Transferred`,`vowsls`.`item_group_master`.`group_code` AS `itemgroup`,round(sum(ifnull(`vowsls`.`scm_issue_hdr`.`issue_value`,0)),0) AS `issuevalue`,round(sum(ifnull((`vowsls`.`scm_return_hdr`.`return_qty` * `vowsls`.`scm_return_hdr`.`return_rate`),0)),0) AS `returnvalue` from ((((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`item_group_master` on(((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`) and (`vowsls`.`item_group_master`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) left join `vowsls`.`scm_issue_hdr` on(((`vowsls`.`scm_issue_hdr`.`sr_line_id` = `vowsls`.`scm_sr_line_item`.`store_line_item_no`) and (`vowsls`.`scm_sr_line_item`.`is_active` = 1) and (`vowsls`.`scm_issue_hdr`.`is_active` = 1) and (`vowsls`.`scm_issue_hdr`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) left join `vowsls`.`scm_return_hdr` on(((`vowsls`.`scm_return_hdr`.`issue_rec_id` = `vowsls`.`scm_issue_hdr`.`issue_no`) and (`vowsls`.`scm_return_hdr`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) where (((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_sr_line_item`.`stock_transer_quantity`) - `vowsls`.`scm_sr_line_item`.`quantity_consumed`) > 0) group by `vowsls`.`scm_sr_hdr`.`company_id`,`vowsls`.`scm_sr_hdr`.`ac_year`,`itemgroup`) `a`;;
CREATE OR REPLACE VIEW view_store_expired_po_list AS select `p`.`company_id` AS `company_id`,`u`.`first_name` AS `Created By`,`l`.`line_item_num` AS `lineitemno`,`cm`.`company_code` AS `Company Code`,`l`.`indent_no` AS `Indent Tran No`,`sili`.`indent_no` AS `Indent No`,round((`l`.`quantity` * `l`.`rate`),0) AS `Value`,`p`.`branch_id` AS `Branch Id`,`bm`.`branch_name` AS `Branch Name`,`p`.`project_id` AS `Project Id`,`pm`.`prj_name` AS `Project Name`,`p`.`fin_year` AS `Ac Year`,`p`.`po_num` AS `Po No`,cast(`p`.`po_date` as date) AS `PO_Date`,`p`.`expected_date` AS `expected_date`,`su`.`supp_name` AS `Supplier Name`,`su`.`supp_code` AS `Supplier Code`,`p`.`po_status` AS `Status Id`,`sm`.`status_name` AS `status_name`,`l`.`group_code` AS `Group Code`,`igm`.`group_desc` AS `Group Name`,`l`.`item_code` AS `Item Code`,`im`.`item_desc` AS `Item Desc`,`l`.`quantity` AS `Po Quantity`,`l`.`gate_po_placed` AS `Inward Quantity`,(`l`.`quantity` - `l`.`gate_po_placed`) AS `Due Value`,(to_days(curdate()) - to_days(`p`.`expected_date`)) AS `Exceeded Days`,`l`.`c_tax` AS `C Tax`,`l`.`s_tax` AS `S tax`,`l`.`i_tax` AS `I Tax`,`l`.`rate` AS `Master Rate`,`l`.`last_purchase_rate` AS `Last Po Rate` from ((((((((((`vowsls`.`scm_po_hdr` `p` join `vowsls`.`scm_po_line_item` `l` on(((`l`.`po_num` = `p`.`po_num`) and (`l`.`is_active` = 1)))) left join `vowsls`.`company_master` `cm` on((`cm`.`comp_id` = `p`.`company_id`))) left join `vowsls`.`branch_master` `bm` on((`bm`.`branch_id` = `p`.`branch_id`))) left join `vowsls`.`project_master` `pm` on((`pm`.`prj_id` = `p`.`project_id`))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `p`.`po_status`))) left join `vowsls`.`item_group_master` `igm` on(((`igm`.`group_code` = `l`.`group_code`) and (`p`.`company_id` = `igm`.`company_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`item_code` = `l`.`item_code`) and (`im`.`group_code` = `l`.`group_code`) and (`im`.`is_active` = 1) and (`im`.`company_id` = `p`.`company_id`)))) left join `vowsls`.`scm_indent_line_item` `sili` on((`sili`.`indent_srl_no` = `l`.`indent_no`))) left join `vowsls`.`suppliermaster` `su` on(((`su`.`supp_code` = `p`.`supp_code`) and (`su`.`company_id` = `p`.`company_id`)))) left join `vowsls`.`user_details` `u` on((`u`.`user_id` = `p`.`created_by`))) where ((`p`.`po_type` <> 'J') and (curdate() > `p`.`expected_date`) and ((`l`.`quantity` - `l`.`gate_po_placed`) > 0));;
CREATE OR REPLACE VIEW view_store_fastfivemoving AS select `i`.`company_id` AS `company_id`,`i`.`fin_year` AS `ac_year`,`i`.`group_code` AS `group_code`,`igm`.`group_desc` AS `group_desc`,`i`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_desc`,round((sum(`i`.`issue_value`) / 10000000),2) AS `issue_value_cr` from ((`vowsls`.`scm_issue_hdr` `i` join `vowsls`.`item_group_master` `igm` on(((`igm`.`company_id` = `i`.`company_id`) and (`igm`.`group_code` = `i`.`group_code`)))) join `vowsls`.`itemmaster` `im` on(((`im`.`company_id` = `i`.`company_id`) and (`im`.`group_code` = `igm`.`group_code`) and (`im`.`item_code` = `i`.`item_code`)))) group by `i`.`company_id`,`i`.`fin_year`,`i`.`group_code`,`igm`.`group_desc`,`i`.`item_code`,`im`.`item_desc` order by sum(`i`.`issue_value`) desc;;
CREATE OR REPLACE VIEW view_store_line_item_wise_issue AS select `h`.`company_id` AS `company_id`,`l`.`store_line_item_no` AS `store_line_item_no`,`l`.`item_grp_id` AS `item_grp_id`,`l`.`item_code` AS `item_code`,`g`.`group_desc` AS `group_desc`,`i`.`item_desc` AS `item_desc`,`l`.`final_qty` AS `final_qty`,`l`.`quantity_consumed` AS `quantity_consumed`,`i`.`uom_code` AS `uom_code`,`l`.`rate` AS `rate`,ifnull(round(sum(`sih`.`issue_qty`),3),0) AS `issued`,`h`.`store_receive_dt` AS `receipt_date`,max(`sih`.`issue_date`) AS `last_issue` from ((((`vowsls`.`scm_sr_line_item` `l` join `vowsls`.`scm_sr_hdr` `h` on(((`h`.`store_receive_no` = `l`.`store_receive_no`) and (`h`.`sr_good_recept_status` <> 4)))) join `vowsls`.`item_group_master` `g` on(((`l`.`item_grp_id` = `g`.`group_code`) and (`h`.`company_id` = `g`.`company_id`)))) join `vowsls`.`itemmaster` `i` on(((`l`.`item_grp_id` = `i`.`group_code`) and (`l`.`item_code` = `i`.`item_code`) and (`h`.`company_id` = `i`.`company_id`)))) left join `vowsls`.`scm_issue_hdr` `sih` on(((`l`.`item_grp_id` = `sih`.`group_code`) and (`l`.`item_code` = `sih`.`item_code`) and (`h`.`company_id` = `sih`.`company_id`) and (`l`.`store_line_item_no` = `sih`.`sr_line_id`) and (`sih`.`is_active` = 1)))) where (`l`.`is_active` = 1) group by `l`.`store_line_item_no`,`l`.`item_grp_id`,`l`.`item_code`,`g`.`group_desc`,`i`.`item_desc`,`l`.`final_qty`,`l`.`quantity_consumed`,`i`.`uom_code`,`l`.`rate`;;
CREATE OR REPLACE VIEW view_store_pending_gate_quantity AS select `l`.`item_code` AS `item_code`,`l`.`group_code` AS `group_code`,`h`.`company_id` AS `company_id`,round(sum((`l`.`quantity` - `l`.`gate_po_placed`)),3) AS `pending_rct_qty` from (`vowsls`.`scm_po_line_item` `l` join `vowsls`.`scm_po_hdr` `h`) where ((`h`.`po_num` = `l`.`po_num`) and (`h`.`po_type` <> 'J') and (`h`.`po_type` <> 'O') and (`l`.`is_active` = 1)) group by `l`.`item_code`,`l`.`group_code`,`h`.`company_id`;;
CREATE OR REPLACE VIEW view_store_pending_inspection_quantity AS select `gh`.`company_id` AS `company_id`,`gl`.`item_grp` AS `item_grp`,`gl`.`item_code` AS `item_code`,round(sum(`gl`.`quantity`),4) AS `pending_inspection` from (`vowsls`.`gate_store_entry_reg_dtl` `gl` join `vowsls`.`gate_store_entry_reg_hdr` `gh`) where ((`gl`.`hdr_id` = `gh`.`hdr_id`) and (`gh`.`inspec_check` = 'N')) group by `gh`.`company_id`,`gl`.`item_grp`,`gl`.`item_code`;;
CREATE OR REPLACE VIEW view_store_pending_po_receipt_qty AS select `il`.`item_code` AS `item_code`,`il`.`group_code` AS `group_code`,`il`.`company_id` AS `company_id`,sum(round((`il`.`indent_qty` - `il`.`po_placed`),3)) AS `pending_qty` from `vowsls`.`scm_indent_line_item` `il` where ((`il`.`indent_type` <> 'J') and (`il`.`indent_type` <> 'O') and (`il`.`is_active` = 1)) group by `il`.`item_code`,`il`.`group_code`,`il`.`company_id`;;
CREATE OR REPLACE VIEW view_store_pending_to_receive_qty AS select `pending_po`.`company_id` AS `company_id`,`pending_po`.`line_item_num` AS `line_item_num`,`pending_po`.`group_code` AS `group_code`,`pending_po`.`item_code` AS `item_code`,`pending_po`.`po_qty` AS `po_qty`,`pending_po`.`received_qty` AS `received_qty`,`pending_po`.`pending_to_receive` AS `pending_to_receive` from (select `p`.`company_id` AS `company_id`,`p`.`line_item_num` AS `line_item_num`,`p`.`group_code` AS `group_code`,`p`.`item_code` AS `item_code`,`p`.`quantity` AS `po_qty`,round(sum(`g`.`approved_qty`),4) AS `received_qty`,round((`p`.`quantity` - sum(`g`.`approved_qty`)),4) AS `pending_to_receive` from (`vowsls`.`scm_po_line_item` `p` join `vowsls`.`gate_store_entry_reg_dtl` `g`) where ((`p`.`line_item_num` = `g`.`po_line_no`) and (`p`.`group_code` <> 999) and (`p`.`is_active` = 1) and (`g`.`is_active` = 1) and (`g`.`approve_reject` > 0)) group by `p`.`company_id`,`p`.`line_item_num`,`p`.`group_code`,`p`.`item_code`,`p`.`quantity`) `pending_po` where (`pending_po`.`pending_to_receive` > 0);;
CREATE OR REPLACE VIEW view_store_po_not_raised AS select `vowsls`.`scm_indent_line_item`.`company_id` AS `company_id`,`vowsls`.`scm_indent_line_item`.`group_code` AS `group_code`,`vowsls`.`scm_indent_line_item`.`item_code` AS `item_code`,round((sum(`vowsls`.`scm_indent_line_item`.`indent_qty`) - sum(`vowsls`.`scm_indent_line_item`.`po_placed`)),2) AS `ind_pending_po` from `vowsls`.`scm_indent_line_item` where ((`vowsls`.`scm_indent_line_item`.`indent_qty` - `vowsls`.`scm_indent_line_item`.`po_placed`) > 0) group by `vowsls`.`scm_indent_line_item`.`company_id`,`vowsls`.`scm_indent_line_item`.`group_code`,`vowsls`.`scm_indent_line_item`.`item_code`;;
CREATE OR REPLACE VIEW view_store_receipt_transfer_issue AS select `sh`.`store_receive_no` AS `tran_hdr_id`,`sl`.`store_line_item_no` AS `tran_line_id`,`sh`.`store_print_no` AS `sr_print_no`,`sh`.`company_id` AS `company_id`,`sh`.`ac_year` AS `ac_year`,`sl`.`item_grp_id` AS `group_code`,`ig`.`group_desc` AS `group_name`,`sl`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`sl`.`uom_code` AS `uom_code`,`sh`.`store_receive_dt` AS `tran_date`,`sh`.`sr_good_recept_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`sh`.`branch_id` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'SR' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,`sl`.`final_qty` AS `received_qty`,`sl`.`rate` AS `rate`,'0' AS `transfer_in_qty`,'0' AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,round((`sl`.`final_qty` * `sl`.`rate`),2) AS `received_val`,'0' AS `transfer_in_val`,'0' AS `transfer_out_val` from (((((`vowsls`.`scm_sr_hdr` `sh` join `vowsls`.`scm_sr_line_item` `sl` on((`sl`.`store_receive_no` = `sh`.`store_receive_no`))) left join `vowsls`.`item_group_master` `ig` on(((`ig`.`company_id` = `sh`.`company_id`) and (`ig`.`group_code` = `sl`.`item_grp_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`company_id` = `sh`.`company_id`) and (`im`.`group_code` = `sl`.`item_grp_id`) and (`im`.`item_code` = `sl`.`item_code`)))) left join `vowsls`.`branch_master` `bm` on(((`bm`.`company_id` = `sh`.`company_id`) and (`sh`.`branch_id` = `bm`.`branch_id`)))) left join `vowsls`.`status_master` `sm` on((`sh`.`sr_good_recept_status` = `sm`.`status_id`))) where ((`sh`.`sr_type` = 'SR') and (`sh`.`supp_code` is not null) and (`sl`.`is_active` = 1)) union select `ih`.`issue_no` AS `tran_hdr_id`,`ih`.`sr_line_id` AS `tran_line_id`,`ih`.`hdr_id` AS `sr_print_no`,`ih`.`company_id` AS `company_id`,`ih`.`fin_year` AS `ac_year`,`ih`.`group_code` AS `group_code`,`ig`.`group_desc` AS `group_name`,`ih`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`ih`.`uom_code` AS `uom_code`,`ih`.`issue_date` AS `tran_date`,`ih`.`issue_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`ih`.`branch_id` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'I' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,'0' AS `received_qty`,`sl`.`rate` AS `rate`,'0' AS `transfer_in_qty`,'0' AS `transfer_out_qty`,`ih`.`issue_qty` AS `issued_qty`,round((`ih`.`issue_qty` * `sl`.`rate`),2) AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,'0' AS `received_val`,'0' AS `transfer_in_val`,'0' AS `transfer_out_val` from (((((`vowsls`.`scm_issue_hdr` `ih` join `vowsls`.`scm_sr_line_item` `sl` on((`ih`.`sr_line_id` = `sl`.`store_line_item_no`))) left join `vowsls`.`item_group_master` `ig` on(((`ig`.`company_id` = `ih`.`company_id`) and (`ig`.`group_code` = `ih`.`group_code`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`company_id` = `ih`.`company_id`) and (`im`.`group_code` = `ih`.`group_code`) and (`im`.`item_code` = `ih`.`item_code`)))) left join `vowsls`.`branch_master` `bm` on(((`bm`.`company_id` = `ih`.`company_id`) and (`ih`.`branch_id` = `bm`.`branch_id`)))) left join `vowsls`.`status_master` `sm` on((`ih`.`issue_status` = `sm`.`status_id`))) where (`ih`.`is_active` = 1) union select `po`.`hdr_id` AS `tran_hdr_id`,`pl`.`line_item_num` AS `tran_line_id`,`po`.`po_num` AS `sr_print_no`,`po`.`company_id` AS `company_id`,`po`.`fin_year` AS `ac_year`,`pl`.`group_code` AS `group_code`,`ig`.`group_desc` AS `group_name`,`pl`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`pl`.`uom` AS `uom_code`,`po`.`po_date` AS `tran_date`,`po`.`po_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`po`.`branch_id` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'PO' AS `tran_type`,`pl`.`quantity` AS `ordered_qty`,`pl`.`rate` AS `ordered_rate`,'0' AS `received_qty`,'0' AS `rate`,'0' AS `transfer_in_qty`,'0' AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,round((`pl`.`quantity` * `pl`.`rate`),0) AS `ordered_val`,'0' AS `received_val`,'0' AS `transfer_in_val`,'0' AS `transfer_out_val` from (((((`vowsls`.`scm_po_hdr` `po` join `vowsls`.`scm_po_line_item` `pl` on(((`pl`.`company_id` = `po`.`company_id`) and (`pl`.`po_num` = `po`.`po_num`)))) left join `vowsls`.`item_group_master` `ig` on(((`ig`.`company_id` = `po`.`company_id`) and (`ig`.`group_code` = `pl`.`group_code`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`company_id` = `po`.`company_id`) and (`im`.`group_code` = `pl`.`group_code`) and (`im`.`item_code` = `pl`.`item_code`)))) left join `vowsls`.`branch_master` `bm` on(((`bm`.`company_id` = `po`.`company_id`) and (`po`.`branch_id` = `bm`.`branch_id`)))) left join `vowsls`.`status_master` `sm` on((`po`.`po_status` = `sm`.`status_id`))) where (`pl`.`is_active` = 1) union select `ret`.`return_no` AS `tran_hdr_id`,'0' AS `tran_line_id`,`ret`.`hdr_id` AS `sr_print_no`,`ret`.`company_id` AS `company_id`,`ret`.`fin_year` AS `ac_year`,`ret`.`group_code` AS `group_code`,`ig`.`group_desc` AS `group_name`,`ret`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`ret`.`uom_code` AS `uom_code`,`ret`.`return_date` AS `tran_date`,`ret`.`return_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`ret`.`branch_id` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'ret' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,'0' AS `received_qty`,'0' AS `rate`,'0' AS `transfer_in_qty`,'0' AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,`ret`.`return_qty` AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,'0' AS `received_val`,'0' AS `transfer_in_val`,'0' AS `transfer_out_val` from ((((`vowsls`.`scm_return_hdr` `ret` left join `vowsls`.`item_group_master` `ig` on(((`ig`.`company_id` = `ret`.`company_id`) and (`ig`.`group_code` = `ret`.`group_code`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`company_id` = `ret`.`company_id`) and (`im`.`group_code` = `ret`.`group_code`) and (`im`.`item_code` = `ret`.`item_code`)))) left join `vowsls`.`branch_master` `bm` on(((`bm`.`company_id` = `ret`.`company_id`) and (`ret`.`branch_id` = `bm`.`branch_id`)))) left join `vowsls`.`status_master` `sm` on((`ret`.`return_status` = `sm`.`status_id`))) where (`ret`.`is_active` = 1) union select `sh`.`store_receive_no` AS `tran_hdr_id`,`sl`.`store_line_item_no` AS `tran_line_id`,`sh`.`store_print_no` AS `sr_print_no`,`sh`.`company_id` AS `company_id`,`sh`.`ac_year` AS `ac_year`,`sl`.`item_grp_id` AS `group_code`,`ig`.`group_desc` AS `group_name`,`sl`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`sl`.`uom_code` AS `uom_code`,`sh`.`store_receive_dt` AS `tran_date`,`sh`.`sr_good_recept_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`sh`.`branch_id` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'STR' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,'0' AS `received_qty`,`sl`.`rate` AS `rate`,`sl`.`final_qty` AS `transfer_in_qty`,'0' AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,'0' AS `received_val`,round((`sl`.`final_qty` * `sl`.`rate`),0) AS `transfer_in_val`,'0' AS `transfer_out_val` from (((((`vowsls`.`scm_sr_hdr` `sh` join `vowsls`.`scm_sr_line_item` `sl` on((`sl`.`store_receive_no` = `sh`.`store_receive_no`))) left join `vowsls`.`item_group_master` `ig` on(((`ig`.`company_id` = `sh`.`company_id`) and (`ig`.`group_code` = `sl`.`item_grp_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`company_id` = `sh`.`company_id`) and (`im`.`group_code` = `sl`.`item_grp_id`) and (`im`.`item_code` = `sl`.`item_code`)))) left join `vowsls`.`branch_master` `bm` on(((`bm`.`company_id` = `sh`.`company_id`) and (`sh`.`branch_id` = `bm`.`branch_id`)))) left join `vowsls`.`status_master` `sm` on((`sh`.`sr_good_recept_status` = `sm`.`status_id`))) where ((`sh`.`sr_type` = 'STR') and (`sl`.`is_active` = 1)) union select `sh`.`store_receive_no` AS `tran_hdr_id`,`sl`.`store_line_item_no` AS `tran_line_id`,`sh`.`store_print_no` AS `sr_print_no`,`sh`.`src_comp` AS `company_id`,`sh`.`ac_year` AS `ac_year`,`sl`.`item_grp_id` AS `group_code`,`ig`.`group_desc` AS `group_name`,`sl`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`sl`.`uom_code` AS `uom_code`,`sh`.`store_receive_dt` AS `tran_date`,`sh`.`sr_good_recept_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`sh`.`src_branch` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'STR' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,'0' AS `received_qty`,`sl`.`rate` AS `rate`,'0' AS `transfer_in_qty`,`sl`.`final_qty` AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,'0' AS `received_val`,'0' AS `transfer_in_val`,round((`sl`.`final_qty` * `sl`.`rate`),0) AS `transfer_out_val` from (((((`vowsls`.`scm_sr_hdr` `sh` join `vowsls`.`scm_sr_line_item` `sl` on((`sl`.`store_receive_no` = `sh`.`store_receive_no`))) left join `vowsls`.`item_group_master` `ig` on(((`ig`.`company_id` = `sh`.`src_comp`) and (`ig`.`group_code` = `sl`.`item_grp_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`company_id` = `sh`.`src_comp`) and (`im`.`group_code` = `sl`.`item_grp_id`) and (`im`.`item_code` = `sl`.`item_code`)))) left join `vowsls`.`branch_master` `bm` on(((`bm`.`company_id` = `sh`.`src_comp`) and (`sh`.`src_branch` = `bm`.`branch_id`)))) left join `vowsls`.`status_master` `sm` on((`sh`.`sr_good_recept_status` = `sm`.`status_id`))) where ((`sh`.`sr_type` = 'STR') and (`sh`.`src_comp` is not null) and (`sl`.`is_active` = 1));;
CREATE OR REPLACE VIEW view_store_receipt_transfer_issue_new AS select `tpi`.`inward_id` AS `tran_hdr_id`,`tpid`.`indent_details_id` AS `tran_line_id`,`tpi`.`store_receipt_no` AS `sr_print_no`,`tpi`.`company` AS `company_id`,`ay`.`year` AS `ac_year`,`tpid`.`item` AS `item`,`im`.`group_code` AS `group_code`,`ig`.`group_desc` AS `group_name`,`im`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`im`.`uom_code` AS `uom_code`,`tpi`.`store_receipt_actual_date` AS `tran_date`,`tpi`.`sr_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`tpi`.`branch` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'SR' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,`tpid`.`approved_qty` AS `received_qty`,`tpid`.`rate` AS `rate`,'0' AS `transfer_in_qty`,'0' AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,round((`tpid`.`approved_qty` * `tpid`.`rate`),2) AS `received_val`,'0' AS `transfer_in_val`,'0' AS `transfer_out_val` from ((((((`vowsls`.`tbl_proc_inward` `tpi` left join `vowsls`.`tbl_proc_inward_detail` `tpid` on((`tpi`.`inward_id` = `tpid`.`inward`))) left join `vowsls`.`itemmaster` `im` on((`tpid`.`item` = `im`.`item_id`))) left join `vowsls`.`item_group_master` `ig` on((`im`.`group_code` = `ig`.`group_code`))) left join `vowsls`.`status_master` `sm` on((`sm`.`status_id` = `tpi`.`sr_status`))) left join `vowsls`.`branch_master` `bm` on((`tpi`.`branch` = `bm`.`branch_id`))) left join `vowsls`.`academic_years` `ay` on(((`tpi`.`store_receipt_actual_date` between `ay`.`from_date` and `ay`.`to_date`) and (`ay`.`company_id` = `tpi`.`company`)))) where (`tpid`.`is_active` = 1) union select `ih`.`issue_no` AS `tran_hdr_id`,`tpmi`.`inward_detail` AS `tran_line_id`,`tpi`.`store_receipt_no` AS `sr_print_no`,`ih`.`company_id` AS `company_id`,`ih`.`fin_year` AS `ac_year`,`ih`.`item_id` AS `item`,`im`.`group_code` AS `group_code`,`ig`.`group_desc` AS `group_name`,`im`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`ih`.`uom_code` AS `uom_code`,`ih`.`issue_date` AS `tran_date`,`ih`.`issue_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`ih`.`branch_id` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'I' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,'0' AS `received_qty`,`tpid`.`rate` AS `rate`,'0' AS `transfer_in_qty`,'0' AS `transfer_out_qty`,`ih`.`issue_qty` AS `issued_qty`,round((`ih`.`issue_qty` * `tpid`.`rate`),2) AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,'0' AS `received_val`,'0' AS `transfer_in_val`,'0' AS `transfer_out_val` from (((((((`vowsls`.`scm_issue_hdr` `ih` left join `vowsls`.`tbl_proc_material_inventory` `tpmi` on((`ih`.`material_inventory_id` = `tpmi`.`material_inventory_id`))) left join `vowsls`.`tbl_proc_inward` `tpi` on((`tpmi`.`inward` = `tpi`.`inward_id`))) left join `vowsls`.`tbl_proc_inward_detail` `tpid` on((`tpmi`.`inward_detail` = `tpid`.`indent_details_id`))) left join `vowsls`.`itemmaster` `im` on((`ih`.`item_id` = `im`.`item_id`))) left join `vowsls`.`item_group_master` `ig` on((`ig`.`group_code` = `im`.`group_code`))) left join `vowsls`.`branch_master` `bm` on((`ih`.`branch_id` = `bm`.`branch_id`))) left join `vowsls`.`status_master` `sm` on((`ih`.`issue_status` = `sm`.`status_id`))) where (`ih`.`is_active` = 1) union select `tpp`.`po_id` AS `tran_hdr_id`,`tppd`.`po_detail_id` AS `tran_line_id`,`tpp`.`po_sequence_no` AS `sr_print_no`,`tpp`.`company` AS `company_id`,`ay`.`year` AS `ac_year`,`tppd`.`item` AS `item`,`im`.`group_code` AS `group_code`,`ig`.`group_desc` AS `group_name`,`im`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`tppd`.`uom_code` AS `uom_code`,`tpp`.`po_approve_date` AS `tran_date`,`tpp`.`status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`tpp`.`branch` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'PO' AS `tran_type`,`tppd`.`qty` AS `ordered_qty`,`tppd`.`rate` AS `ordered_rate`,'0' AS `received_qty`,'0' AS `rate`,'0' AS `transfer_in_qty`,'0' AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,round((`tppd`.`qty` * `tppd`.`rate`),0) AS `ordered_val`,'0' AS `received_val`,'0' AS `transfer_in_val`,'0' AS `transfer_out_val` from ((((((`vowsls`.`tbl_proc_po` `tpp` left join `vowsls`.`tbl_proc_po_detail` `tppd` on((`tpp`.`po_id` = `tppd`.`po`))) left join `vowsls`.`itemmaster` `im` on((`tppd`.`item` = `im`.`item_id`))) left join `vowsls`.`item_group_master` `ig` on((`im`.`group_code` = `ig`.`group_code`))) left join `vowsls`.`branch_master` `bm` on((`tpp`.`branch` = `bm`.`branch_id`))) left join `vowsls`.`status_master` `sm` on((`tpp`.`status` = `sm`.`status_id`))) left join `vowsls`.`academic_years` `ay` on(((`tpp`.`po_approve_date` between `ay`.`from_date` and `ay`.`to_date`) and (`ay`.`company_id` = `tpp`.`company`)))) where (`tppd`.`is_active` = 1) union select `sh`.`store_receive_no` AS `tran_hdr_id`,`sl`.`store_line_item_no` AS `tran_line_id`,`sh`.`store_print_no` AS `sr_print_no`,`sh`.`company_id` AS `company_id`,`sh`.`ac_year` AS `ac_year`,NULL AS `item`,`sl`.`item_grp_id` AS `group_code`,`ig`.`group_desc` AS `group_name`,`sl`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`sl`.`uom_code` AS `uom_code`,`sh`.`store_receive_dt` AS `tran_date`,`sh`.`sr_good_recept_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`sh`.`branch_id` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'STR' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,'0' AS `received_qty`,`sl`.`rate` AS `rate`,`sl`.`final_qty` AS `transfer_in_qty`,'0' AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,'0' AS `received_val`,round((`sl`.`final_qty` * `sl`.`rate`),0) AS `transfer_in_val`,'0' AS `transfer_out_val` from (((((`vowsls`.`scm_sr_hdr` `sh` join `vowsls`.`scm_sr_line_item` `sl` on((`sl`.`store_receive_no` = `sh`.`store_receive_no`))) left join `vowsls`.`item_group_master` `ig` on(((`ig`.`company_id` = `sh`.`company_id`) and (`ig`.`group_code` = `sl`.`item_grp_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`company_id` = `sh`.`company_id`) and (`im`.`group_code` = `sl`.`item_grp_id`) and (`im`.`item_code` = `sl`.`item_code`)))) left join `vowsls`.`branch_master` `bm` on(((`bm`.`company_id` = `sh`.`company_id`) and (`sh`.`branch_id` = `bm`.`branch_id`)))) left join `vowsls`.`status_master` `sm` on((`sh`.`sr_good_recept_status` = `sm`.`status_id`))) where ((`sh`.`sr_type` = 'STR') and (`sl`.`is_active` = 1)) union select `sh`.`store_receive_no` AS `tran_hdr_id`,`sl`.`store_line_item_no` AS `tran_line_id`,`sh`.`store_print_no` AS `sr_print_no`,`sh`.`src_comp` AS `company_id`,`sh`.`ac_year` AS `ac_year`,NULL AS `item`,`sl`.`item_grp_id` AS `group_code`,`ig`.`group_desc` AS `group_name`,`sl`.`item_code` AS `item_code`,`im`.`item_desc` AS `item_name`,`sl`.`uom_code` AS `uom_code`,`sh`.`store_receive_dt` AS `tran_date`,`sh`.`sr_good_recept_status` AS `tran_status`,`sm`.`status_name` AS `status_name`,`sh`.`src_branch` AS `branch_id`,`bm`.`branch_name` AS `branch_name`,'STR' AS `tran_type`,'0' AS `ordered_qty`,'0' AS `ordered_rate`,'0' AS `received_qty`,`sl`.`rate` AS `rate`,'0' AS `transfer_in_qty`,`sl`.`final_qty` AS `transfer_out_qty`,'0' AS `issued_qty`,'0' AS `issued_val`,'0' AS `store_return_qty`,'0' AS `store_return_val`,'0' AS `ordered_val`,'0' AS `received_val`,'0' AS `transfer_in_val`,round((`sl`.`final_qty` * `sl`.`rate`),0) AS `transfer_out_val` from (((((`vowsls`.`scm_sr_hdr` `sh` join `vowsls`.`scm_sr_line_item` `sl` on((`sl`.`store_receive_no` = `sh`.`store_receive_no`))) left join `vowsls`.`item_group_master` `ig` on(((`ig`.`company_id` = `sh`.`src_comp`) and (`ig`.`group_code` = `sl`.`item_grp_id`)))) left join `vowsls`.`itemmaster` `im` on(((`im`.`company_id` = `sh`.`src_comp`) and (`im`.`group_code` = `sl`.`item_grp_id`) and (`im`.`item_code` = `sl`.`item_code`)))) left join `vowsls`.`branch_master` `bm` on(((`bm`.`company_id` = `sh`.`src_comp`) and (`sh`.`src_branch` = `bm`.`branch_id`)))) left join `vowsls`.`status_master` `sm` on((`sh`.`sr_good_recept_status` = `sm`.`status_id`))) where ((`sh`.`sr_type` = 'STR') and (`sh`.`src_comp` is not null) and (`sl`.`is_active` = 1));;
CREATE OR REPLACE VIEW view_store_stock_consumption_wise_widget AS select `a`.`company_id` AS `company_id`,`a`.`itemgroup` AS `itemgroup`,`a`.`value` AS `value`,`a`.`Stock` AS `stock` from (select `vowsls`.`view_store_consumption_categoryWise`.`company_id` AS `company_id`,`vowsls`.`view_store_consumption_categoryWise`.`itemgroup` AS `itemgroup`,'Open' AS `value`,`vowsls`.`view_store_consumption_categoryWise`.`opening` AS `Stock` from `vowsls`.`view_store_consumption_categoryWise` union select `vowsls`.`view_store_consumption_categoryWise`.`company_id` AS `company_id`,`vowsls`.`view_store_consumption_categoryWise`.`itemgroup` AS `itemgroup`,'Transfer' AS `value`,`vowsls`.`view_store_consumption_categoryWise`.`Transferred` AS `stock` from `vowsls`.`view_store_consumption_categoryWise` union select `vowsls`.`view_store_consumption_categoryWise`.`company_id` AS `company_id`,`vowsls`.`view_store_consumption_categoryWise`.`itemgroup` AS `itemgroup`,'Issue' AS `value`,`vowsls`.`view_store_consumption_categoryWise`.`issuevalue` AS `stock` from `vowsls`.`view_store_consumption_categoryWise` union select `vowsls`.`view_store_consumption_categoryWise`.`company_id` AS `company_id`,`vowsls`.`view_store_consumption_categoryWise`.`itemgroup` AS `itemgroup`,'Return' AS `value`,`vowsls`.`view_store_consumption_categoryWise`.`returnvalue` AS `stock` from `vowsls`.`view_store_consumption_categoryWise` union select `vowsls`.`view_store_consumption_categoryWise`.`company_id` AS `company_id`,`vowsls`.`view_store_consumption_categoryWise`.`itemgroup` AS `itemgroup`,'Final' AS `value`,`vowsls`.`view_store_consumption_categoryWise`.`closingvalue` AS `stock` from `vowsls`.`view_store_consumption_categoryWise`) `a` where (`a`.`itemgroup` is not null);;
CREATE OR REPLACE VIEW view_store_stock_inventory_category_wise AS select `a`.`company_id` AS `company_id`,`a`.`opening` AS `opening`,`a`.`receivedvalue` AS `receivedvalue`,`a`.`pending` AS `pending`,`a`.`itemgroup` AS `itemgroup`,`a`.`poplaced` AS `poplaced`,((`a`.`opening` + `a`.`receivedvalue`) - `a`.`pending`) AS `finalstock`,`a`.`indent` AS `indent` from (select `vowsls`.`scm_sr_hdr`.`company_id` AS `company_id`,round(sum((((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_sr_line_item`.`stock_transer_quantity`) - `vowsls`.`scm_sr_line_item`.`quantity_consumed`) * `vowsls`.`scm_sr_line_item`.`rate`)),2) AS `opening`,round(sum((`vowsls`.`scm_sr_line_item`.`final_qty` * `vowsls`.`scm_sr_line_item`.`rate`)),0) AS `receivedvalue`,round(sum(((`vowsls`.`scm_sr_line_item`.`final_qty` - `vowsls`.`scm_sr_line_item`.`quantity_consumed`) * `vowsls`.`scm_sr_line_item`.`rate`)),0) AS `pending`,`vowsls`.`item_group_master`.`group_code` AS `itemgroup`,round(sum(((`vowsls`.`scm_po_line_item`.`quantity` - `vowsls`.`scm_po_line_item`.`gate_po_placed`) * `vowsls`.`scm_po_line_item`.`rate`)),0) AS `poplaced`,round(sum(((`vowsls`.`scm_indent_line_item`.`indent_qty` - `vowsls`.`scm_indent_line_item`.`po_placed`) * `vowsls`.`scm_indent_line_item`.`rate`)),0) AS `indent` from (((((`vowsls`.`scm_sr_hdr` join `vowsls`.`scm_sr_line_item` on((`vowsls`.`scm_sr_hdr`.`store_receive_no` = `vowsls`.`scm_sr_line_item`.`store_receive_no`))) join `vowsls`.`item_group_master` on(((`vowsls`.`item_group_master`.`group_code` = `vowsls`.`scm_sr_line_item`.`item_grp_id`) and (`vowsls`.`item_group_master`.`company_id` = `vowsls`.`scm_sr_hdr`.`company_id`)))) join `vowsls`.`gate_store_entry_reg_dtl` on((`vowsls`.`gate_store_entry_reg_dtl`.`dtl_id` = `vowsls`.`scm_sr_line_item`.`gate_line_item_no`))) join `vowsls`.`scm_po_line_item` on((`vowsls`.`scm_po_line_item`.`line_item_num` = `vowsls`.`gate_store_entry_reg_dtl`.`dtl_id`))) join `vowsls`.`scm_indent_line_item` on((`vowsls`.`scm_indent_line_item`.`indent_srl_no` = `vowsls`.`scm_po_line_item`.`indent_no`))) group by `vowsls`.`scm_sr_hdr`.`company_id`,`itemgroup` order by `itemgroup`) `a`;;
CREATE OR REPLACE VIEW view_store_stock_inventory_status AS select `i`.`company_id` AS `company_id`,`i`.`group_code` AS `group_code`,`i`.`item_code` AS `item_id`,concat(`i`.`group_code`,`i`.`item_code`) AS `item_cod`,`i`.`item_desc` AS `item_desc`,`i`.`max_order_value` AS `min_qty`,`vowsls`.`sr`.`stockbal` AS `stockbal`,`i`.`max_value` AS `max_qty`,`vowsls`.`pnr`.`ind_pending_po` AS `Indented_Pending_to_raise_po`,`vowsls`.`prq`.`pending_to_receive` AS `pending_from_party`,`vowsls`.`piq`.`pending_inspection` AS `pending_at_inspection`,round(((((ifnull(`vowsls`.`sr`.`stockbal`,0) + ifnull(`vowsls`.`pnr`.`ind_pending_po`,0)) + ifnull(`vowsls`.`prq`.`pending_to_receive`,0)) + ifnull(`vowsls`.`piq`.`pending_inspection`,0)) - ifnull(`i`.`max_value`,0)),4) AS `excess_stock`,round(((((ifnull(`i`.`max_order_value`,0) - ifnull(`vowsls`.`sr`.`stockbal`,0)) - ifnull(`vowsls`.`pnr`.`ind_pending_po`,0)) - ifnull(`vowsls`.`prq`.`pending_to_receive`,0)) - ifnull(`vowsls`.`piq`.`pending_inspection`,0)),4) AS `to_be_indented` from ((((`vowsls`.`itemmaster` `i` left join `vowsls`.`store_stock_report` `sr` on(((`i`.`company_id` = `vowsls`.`sr`.`company_id`) and (`i`.`group_code` = `vowsls`.`sr`.`item_grp_id`) and (`i`.`item_code` = `vowsls`.`sr`.`item_code`)))) left join `vowsls`.`view_store_po_not_raised` `pnr` on(((`i`.`company_id` = `vowsls`.`pnr`.`company_id`) and (`i`.`group_code` = `vowsls`.`pnr`.`group_code`) and (`i`.`item_code` = `vowsls`.`pnr`.`item_code`)))) left join `vowsls`.`view_store_pending_to_receive_qty` `prq` on(((`i`.`company_id` = `vowsls`.`prq`.`company_id`) and (`i`.`group_code` = `vowsls`.`prq`.`group_code`) and (`i`.`item_code` = `vowsls`.`prq`.`item_code`)))) left join `vowsls`.`view_store_pending_inspection_quantity` `piq` on(((`i`.`company_id` = `vowsls`.`piq`.`company_id`) and (`i`.`group_code` = `vowsls`.`piq`.`item_grp`) and (`i`.`item_code` = `vowsls`.`piq`.`item_code`)))) where (((`i`.`max_value` > 0) or (`i`.`max_order_value` > 0)) and (`i`.`group_code` <> 999));;
CREATE OR REPLACE VIEW view_store_stock_summary_values AS select (select ((round(sum((`srl`.`final_qty` * `srl`.`rate`)),0) - round(sum((`srl`.`quantity_consumed` * `srl`.`rate`)),0)) - round(sum((`srl`.`stock_transer_quantity` * `srl`.`rate`)),0)) AS `open` from (`vowsls`.`scm_sr_line_item` `srl` join `vowsls`.`scm_sr_hdr` `srh`) where ((`srh`.`store_receive_no` = `srl`.`store_receive_no`) and (`srh`.`store_receive_dt` < (last_day(now()) - interval (dayofmonth(last_day(now())) - 1) day)) and (`srh`.`company_id` = `sh`.`company_id`) and (`srl`.`is_active` = 1))) AS `Open`,(select round(sum(((`l`.`indent_qty` - `l`.`po_placed`) * `l`.`rate`)),0) from (`vowsls`.`scm_indent_line_item` `l` join `vowsls`.`scm_indent_hdr` `h`) where ((`l`.`company_id` = `sh`.`company_id`) and (`h`.`indent_status` = '3') and (`h`.`fin_year` = `l`.`fin_year`) and (`h`.`company_id` = `l`.`company_id`) and (`h`.`indent_no` = `l`.`indent_no`) and (`l`.`is_active` = 1) and (`l`.`indent_type` <> 'J'))) AS `Indent`,(select round(sum(((`pl`.`quantity` - `pl`.`gate_po_placed`) * `pl`.`rate`)),0) from (`vowsls`.`scm_po_line_item` `pl` join `vowsls`.`scm_po_hdr` `p`) where ((`p`.`po_num` = `pl`.`po_num`) and (`p`.`po_type` <> 'J') and (`p`.`po_status` = '3') and (`pl`.`is_active` = 1) and (`p`.`company_id` = `sh`.`company_id`))) AS `Po`,round(sum((`sl`.`final_qty` * `sl`.`rate`)),0) AS `Receipt`,(select round(sum(`ish`.`issue_value`),0) from `vowsls`.`scm_issue_hdr` `ish` where ((`ish`.`issue_date` >= (last_day(now()) - interval (dayofmonth(last_day(now())) - 1) day)) and (`ish`.`is_active` = 1) and (`ish`.`company_id` = `sh`.`company_id`))) AS `Issue`,round(sum((`sl`.`stock_transer_quantity` * `sl`.`rate`)),0) AS `Transfer`,(((select ((round(sum((`srl`.`final_qty` * `srl`.`rate`)),0) - round(sum((`srl`.`quantity_consumed` * `srl`.`rate`)),0)) - round(sum((`srl`.`stock_transer_quantity` * `srl`.`rate`)),0)) AS `open` from (`vowsls`.`scm_sr_line_item` `srl` join `vowsls`.`scm_sr_hdr` `srh`) where ((`srh`.`store_receive_no` = `srl`.`store_receive_no`) and (`srh`.`store_receive_dt` < (last_day(now()) - interval (dayofmonth(last_day(now())) - 1) day)) and (`srh`.`company_id` = `sh`.`company_id`) and (`srl`.`is_active` = 1))) + round((sum((`sl`.`final_qty` * `sl`.`rate`)) - sum((`sl`.`stock_transer_quantity` * `sl`.`rate`))),0)) - ifnull((select round(sum(`ish`.`issue_value`),0) from `vowsls`.`scm_issue_hdr` `ish` where ((`ish`.`issue_date` >= (last_day(now()) - interval (dayofmonth(last_day(now())) - 1) day)) and (`ish`.`is_active` = 1) and (`ish`.`company_id` = `sh`.`company_id`))),0)) AS `Final`,`sh`.`company_id` AS `company_id` from (`vowsls`.`scm_sr_line_item` `sl` join `vowsls`.`scm_sr_hdr` `sh` on(((`sh`.`store_receive_no` = `sl`.`store_receive_no`) and (`sl`.`is_active` = 1) and (`sh`.`store_receive_dt` >= (last_day(now()) - interval (dayofmonth(last_day(now())) - 1) day))))) group by `sh`.`company_id`;;
CREATE OR REPLACE VIEW view_store_summary_value_wid AS select `b`.`company_id` AS `company_id`,`b`.`disp_order` AS `disp_order`,`b`.`order` AS `order`,`b`.`word` AS `word`,`b`.`val` AS `val` from (select `vowsls`.`view_store_stock_summary_values`.`company_id` AS `company_id`,'Open' AS `disp_order`,'1' AS `order`,'Open' AS `word`,`vowsls`.`view_store_stock_summary_values`.`Open` AS `val` from `vowsls`.`view_store_stock_summary_values` union select `vowsls`.`view_store_stock_summary_values`.`company_id` AS `company_id`,'Indent' AS `disp_order`,'2' AS `order`,'Indent' AS `word`,`vowsls`.`view_store_stock_summary_values`.`Indent` AS `val` from `vowsls`.`view_store_stock_summary_values` union select `vowsls`.`view_store_stock_summary_values`.`company_id` AS `company_id`,'PO' AS `disp_order`,'3' AS `order`,'PO' AS `word`,`vowsls`.`view_store_stock_summary_values`.`Po` AS `val` from `vowsls`.`view_store_stock_summary_values` union select `vowsls`.`view_store_stock_summary_values`.`company_id` AS `company_id`,'Receipt' AS `disp_order`,'4' AS `order`,'Receipt' AS `word`,`vowsls`.`view_store_stock_summary_values`.`Receipt` AS `val` from `vowsls`.`view_store_stock_summary_values` union select `vowsls`.`view_store_stock_summary_values`.`company_id` AS `company_id`,'Issue' AS `disp_order`,'5' AS `order`,'Issue' AS `word`,`vowsls`.`view_store_stock_summary_values`.`Issue` AS `val` from `vowsls`.`view_store_stock_summary_values` union select `vowsls`.`view_store_stock_summary_values`.`company_id` AS `company_id`,'Transfer' AS `disp_order`,'6' AS `order`,'Transfer' AS `word`,`vowsls`.`view_store_stock_summary_values`.`Transfer` AS `val` from `vowsls`.`view_store_stock_summary_values` union select `vowsls`.`view_store_stock_summary_values`.`company_id` AS `company_id`,'Final' AS `disp_order`,'7' AS `order`,'Final' AS `word`,`vowsls`.`view_store_stock_summary_values`.`Final` AS `val` from `vowsls`.`view_store_stock_summary_values`) `b` order by `b`.`company_id`,`b`.`order`;;
CREATE OR REPLACE VIEW view_workerall AS select `w`.`eb_id` AS `eb_id`,`w`.`active` AS `active`,`w`.`cata_id` AS `cata_id`,`c`.`cata_desc` AS `cata_desc`,`w`.`company_id` AS `company_id`,`d`.`dept_desc` AS `dept_desc`,`w`.`dept_id` AS `dept_id`,`w`.`eb_no` AS `eb_no`,`w`.`esi_no` AS `esi_no`,`d`.`mdept_id` AS `mdept_id`,`de`.`desig` AS `desig`,`w`.`desg_id` AS `desg_id`,`w`.`pf_no` AS `pf_no`,`w`.`worker_name` AS `worker_name`,`md`.`dept_desc` AS `mdept_desc` from ((((`vowsls`.`worker_master` `w` left join `vowsls`.`designation` `de` on((`de`.`id` = `w`.`desg_id`))) left join `vowsls`.`category_master` `c` on((`c`.`cata_id` = `w`.`cata_id`))) left join `vowsls`.`department_master` `d` on((`d`.`dept_id` = `w`.`dept_id`))) left join `vowsls`.`master_department` `md` on((`md`.`mdept_id` = `d`.`mdept_id`))) where ((`d`.`company_id` = `w`.`company_id`) and (`c`.`company_id` = `w`.`company_id`) and (`de`.`company_id` = `w`.`company_id`) and (`md`.`company_id` = `d`.`company_id`));;
