Arafath10 commited on
Commit
4ec3e1e
1 Parent(s): 9cc418e

Update data_collector.py

Browse files
Files changed (1) hide show
  1. data_collector.py +50 -53
data_collector.py CHANGED
@@ -54,58 +54,49 @@ def get_data(b_id,product_name):
54
 
55
  # Define the SQL SELECT query
56
  sql_query = f"""
57
- SELECT
58
- `b`.`id` AS `business_id`,
59
- `b`.`name` AS `business_name`,
60
- `p`.`name` AS `product_name`,
61
- `p`.`type` AS `product_type`,
62
- `c1`.`name` AS `category_name`,
63
- `pv`.`name` AS `product_variation`,
64
- `v`.`name` AS `variation_name`,
65
- `v`.`sub_sku`,
66
- `c`.`name` AS `customer`,
67
- `c`.`contact_id`,
68
- `t`.`id` AS `transaction_id`,
69
- `t`.`invoice_no`,
70
- `t`.`transaction_date` AS `transaction_date`,
71
- (transaction_sell_lines.quantity - transaction_sell_lines.quantity_returned) AS sell_qty,
72
- `u`.`short_name` AS `unit`,
73
- transaction_sell_lines.unit_price_inc_tax,
74
- transaction_sell_lines.unit_price_before_discount
75
- FROM `transaction_sell_lines`
76
- INNER JOIN `transactions` AS `t`
77
- ON `transaction_sell_lines`.`transaction_id` = `t`.`id`
78
- INNER JOIN `variations` AS `v`
79
- ON `transaction_sell_lines`.`variation_id` = `v`.`id`
80
- LEFT JOIN `transaction_sell_lines_purchase_lines` AS `tspl`
81
- ON `transaction_sell_lines`.`id` = `tspl`.`sell_line_id`
82
- LEFT JOIN `purchase_lines` AS `pl`
83
- ON `tspl`.`purchase_line_id` = `pl`.`id`
84
- INNER JOIN `product_variations` AS `pv`
85
- ON `v`.`product_variation_id` = `pv`.`id`
86
- INNER JOIN `contacts` AS `c`
87
- ON `t`.`contact_id` = `c`.`id`
88
- INNER JOIN `products` AS `p`
89
- ON `pv`.`product_id` = `p`.`id`
90
- LEFT JOIN `business` AS `b`
91
- ON `p`.`business_id` = `b`.`id`
92
- LEFT JOIN `categories` AS `c1`
93
- ON `p`.`category_id` = `c1`.`id`
94
- LEFT JOIN `tax_rates`
95
- ON `transaction_sell_lines`.`tax_id` = `tax_rates`.`id`
96
- LEFT JOIN `units` AS `u`
97
- ON `p`.`unit_id` = `u`.`id`
98
- LEFT JOIN `transaction_payments` AS `tp`
99
- ON `tp`.`transaction_id` = `t`.`id`
100
- LEFT JOIN `transaction_sell_lines` AS `tsl`
101
- ON `transaction_sell_lines`.`parent_sell_line_id` = `tsl`.`id`
102
- WHERE `t`.`type` = 'sell'
103
- AND `t`.`status` = 'final'
104
- AND `t`.`business_id` = {b_id}
105
- GROUP BY `b`.`id`,
106
- `transaction_sell_lines`.`id`;
107
- """
108
-
109
  # Execute the SQL query
110
  cursor.execute(sql_query)
111
 
@@ -126,7 +117,13 @@ def get_data(b_id,product_name):
126
  connection.close()
127
 
128
  # Create a DataFrame
129
- columns = ["business_id","business_name","product_name","product_type","category_name","product_variation","variation_name","sub_sku","customer","contact_id","transaction_id","invoice_no","transaction_date","sell_qty","unit","cost_price","selling_price"]
 
 
 
 
 
 
130
  df = pd.DataFrame(results, columns=columns)
131
  return df,"done"
132
 
 
54
 
55
  # Define the SQL SELECT query
56
  sql_query = f"""
57
+ SELECT
58
+ b.id AS business_id,
59
+ b.name AS business_name,
60
+ p.name AS product_name,
61
+ p.type AS product_type,
62
+ c1.name AS category_name,
63
+ br.name AS brand_name,
64
+ p.image AS product_image,
65
+ pv.name AS product_variation,
66
+ v.name AS variation_name,
67
+ v.sub_sku,
68
+ c.name AS customer,
69
+ c.contact_id,
70
+ t.id AS transaction_id,
71
+ t.invoice_no,
72
+ t.transaction_date AS transaction_date,
73
+ (transaction_sell_lines.quantity - transaction_sell_lines.quantity_returned) AS sell_qty,
74
+ u.short_name AS unit,
75
+ transaction_sell_lines.unit_price_inc_tax,
76
+ transaction_sell_lines.unit_price_before_discount
77
+ FROM
78
+ transaction_sell_lines
79
+ INNER JOIN transactions AS t ON transaction_sell_lines.transaction_id = t.id
80
+ INNER JOIN variations AS v ON transaction_sell_lines.variation_id = v.id
81
+ LEFT JOIN transaction_sell_lines_purchase_lines AS tspl ON transaction_sell_lines.id = tspl.sell_line_id
82
+ LEFT JOIN purchase_lines AS pl ON tspl.purchase_line_id = pl.id
83
+ INNER JOIN product_variations AS pv ON v.product_variation_id = pv.id
84
+ INNER JOIN contacts AS c ON t.contact_id = c.id
85
+ INNER JOIN products AS p ON pv.product_id = p.id
86
+ LEFT JOIN business AS b ON p.business_id = b.id
87
+ LEFT JOIN categories AS c1 ON p.category_id = c1.id
88
+ LEFT JOIN brands AS br ON p.brand_id = br.id
89
+ LEFT JOIN tax_rates ON transaction_sell_lines.tax_id = tax_rates.id
90
+ LEFT JOIN units AS u ON p.unit_id = u.id
91
+ LEFT JOIN transaction_payments AS tp ON tp.transaction_id = t.id
92
+ LEFT JOIN transaction_sell_lines AS tsl ON transaction_sell_lines.parent_sell_line_id = tsl.id
93
+ WHERE
94
+ t.type = 'sell'
95
+ AND t.status = 'final'
96
+ AND t.business_id = {b_id}
97
+ GROUP BY
98
+ b.id, transaction_sell_lines.id;
99
+ """
 
 
 
 
 
 
 
 
 
100
  # Execute the SQL query
101
  cursor.execute(sql_query)
102
 
 
117
  connection.close()
118
 
119
  # Create a DataFrame
120
+ columns = [
121
+ "business_id", "business_name", "product_name", "product_type",
122
+ "category_name", "brand_name", "product_image", "product_variation",
123
+ "variation_name", "sub_sku", "customer", "contact_id",
124
+ "transaction_id", "invoice_no", "transaction_date", "sell_qty",
125
+ "unit", "unit_price_inc_tax", "unit_price_before_discount"
126
+ ]
127
  df = pd.DataFrame(results, columns=columns)
128
  return df,"done"
129