title: Need store procedure to calculate from these two tables
body: <p>I should do this in xampp need an sp structure for this as i am a beginner if possible help to give complete sp for this scenario with detailed explanantion. Other structure like crud operations has been done with php,javascript</p>
  
  <pre><code>1. SELECT `cid`, `parent_cat`, `category_name`, `category_life`, `status` FROM `categories`
  2. SELECT `pid`, `cid`, `bid`, `product_name`, `product_price`, `product_stock`, `added_date`, `p_status`, `loc`, `in_no`, `gst_no`, `cgst`, `sgst`, `igst`, `total`, `depre`, `pur_from` FROM `products` 
  </code></pre>
  
  <p>From the above two table's i should fetch record and calculate those fields and insert in the below table:</p>
  
  <pre><code>3. SELECT `elapsed_yend`, `remaining_days`, `depreciation_cur`, `current_wdv`, `depreciation_next`, `next_wdv`, `accumulate_depre`, `sale_amount`, `pro_los`, `end_date` FROM `calculation` 
  </code></pre>
  
  <p>Example, these calculation should happen in products table:</p>
  
  <pre><code>CGST:
      cgst = product_price * 09
      sgst = product_price * 09
      igst = product_price * 09
  
  if status is 1 it should calculate  igst other cgst,sgst must be 0(zero)
               0 it should calculate  cgst,sgst other igst  must be 0(zero)
  
          Depreciation Amount:
  
              depre = product_price + .5(cgst+sgst+igst)
  
  
  Elapsede year end :
          elapsed_yend = added_date(from products table (No:2)) till every year 31/March/xxxx.
  
          Number of days between these two dates
  
      remaining_days = category_life - (date difference between added_date(from products (No:1)) till date)
  
      category_life(from categories table (No:1))Ex:mobile it's life will be 1080 days.
  
      Current Year depreciation:
          depreciation_cur  = (depre/category_life)*elapsed_yend
  
      Current Year Written down value:
  
          current_wdv  = depre - depreciation_cur
  
      Next Year depreciation :
  
          depreciation_next = (depre / category_life) * D
          D = days difference between every year 01/April/xxxx till end_date(from calculation table)
  
      Next Year Written down value:   
  
          next_wdv = current_wdv - depreciation_next
  
      Accumulate Depreciation :
  
          accumulate_depre = depreciation_cur + depreciation_next
  </code></pre>